$(document).ready(function () {


	$('#video').empty();
	
	//remove last border for home bottom menu
	$('#homeBottomLinks p a:last').css('border','0');
	
	//make home botttom links rollover-able
	
 	// - put images as backgrounds. 
 	
	if( $('#homeBottomLinks').length > 0 ){
		$( "#homeBottomLinks a" ).each(
			function(i){
				src = $(this).children('img').attr('src');
				$(this).css({'background':'url('+src+') no-repeat'});
				$(this).children('img').hide();
			}
		);
	}
 	
	if( $('#mainMenu').length > 0 ){
		$( "#mainMenu ul li" ).each(
			function(i){
				if(i < $( "#mainMenu ul li" ).length -1){
					$('#mainMenu ul li:eq('+i+')').append('<img src="assets/comp/sep-main-menu.gif" alt="" style="vertical-align: middle"/>');
				}
			}
		);
	}
	
	if( $('#applyNow').length > 0 ){
		$('#applyNow h3').after('<span class="applyNowSeparator"></span>');
		$('#applyNow ul li').append('<span class="applyNowSeparator"></span>');
		$('#applyNow ul li a').append('<img src="assets/comp/arrow-right-red.gif" alt="">');
	}
	
	if( $('.faqSection').length > 0 ){
		
		$("h4.question").click(function () {
	      $(this).next('div').slideToggle();
	      $(this).toggleClass('openQuestion');
	    }).next('div').hide();
	    
	    $('div.answer').after('<img src="assets/comp/separator-faq.png" alt="">');
	    
	}
	
	if( $('.repTitle').length > 0 ){
		
		$("h4.repTitle").click(function () {
	      $(this).next('div').slideToggle();
	      $(this).toggleClass('openRepTitle');
	    }).next('div').hide();
	    
	    $('div.repContent').after('<img src="assets/comp/separator-faq.png" alt="">');
	    
	}
	
	
	if( $('.newsTitle').length > 0 ){
		
		$("h4.newsTitle").click(function () {
	      $(this).next('div').slideToggle();
	      $(this).toggleClass('openNewsTitle');
	    }).next('div').hide();
	    
	     $('div.newsContent').after('<img src="assets/comp/separator.png" alt="">');
	}
	
	if( $('.reasonTitle').length > 0 ){
		$("h4.reasonTitle").append('<img src="assets/comp/arrow-right-red.gif" alt="" style="margin-left:3px">');
		
		$("h4.reasonTitle").click(function () {
	      $(this).next('div').slideToggle();
	    }).next('div').hide();
	    
	    $('div.reason').after('<img src="assets/comp/separator.png" alt="">');
	    
	}
	
	
	if($('#carousel').length > 0){
	  /*testimonial carousel*/
	  $("#carousel div.nav").jCarouselLite({
	    	btnNext: ".next",
	    	btnPrev: ".prev",
	    	visible: 4
	  });
	} 
	
	$.each( $("#monthlyEvents ul li.monthlyEvents"), function(i, n){
		  //$(this).addClass(''+i);
	});

	if($('#monthlyEvents').length > 0){
	
		//get index of the current month element
		var index = $('#monthlyEvents ul li').index( $('.current',$('ul')) );
		//set first month title 
		$('#monthlyEventsNav .month').text($('#monthlyEvents ul li.current').children('div').children('h3.monthlyEventTiltle').text())			
		//set start height
		var nH = $('#monthlyEvents ul li.current').children('div').height();
		$("#monthlyEventsWrapper").height(nH+40);
				
		$("#monthlyEvents").jCarouselLite({
			btnNext: ".nextMonthlyEvent",
			btnPrev: ".prevMonthlyEvent",
			visible: 1,
			circular: false,
			start: index,
			afterEnd: function(els) {
				var el = els[0];
				$('#monthlyEventsNav .month').text($(el).children('div').children('h3.monthlyEventTiltle').text());
				var nH = $(el).children('div').height();
				$("#monthlyEventsWrapper").height(nH+40);
			}
		});
	} 
	
	//wrap highlight in valign table in order to aign it in the middle
	$hHtml = $('#highlight').html();
	$hH = $('#highlight').height();
	$('#highlight').empty();
	$('#highlight').html('<table><tr><td style="vertical-align:bottom;height:'+ $hH +'px">' + $hHtml + '</td><tr></table>');
	
	//countries list
	$('select#countriesDropDown').change(function () {
		var str = "";
		$("select option:selected").each(function () {
			//str += $(this).value() + " ";
			//alert($(this).val());
			$('.country').hide();
			$('#country-'+$(this).val()).show();
		});
	}).change();
	
	//languages list
	$('select#languagesDropDown').change(function () {
		var str = "";
		$("select option:selected").each(function () {
			$('.language').hide();
			$('#language-'+$(this).val()).show();
		});
	}).change();
	
	//app form styles
	$("#applicationForm input[type='text']").addClass("inputText");
	
});


$(window).load(function () {	

	///rolover with images
	$("#mainMenu ul li:not(.active) a span img").hover(
			function () {
				var oldSrc = $(this).attr('src');
				var newSrc = oldSrc.replace('7f7f99', 'b5202a');
				$(this).attr('src', newSrc);
			}, 
			function (i) {
				var oldSrc = $(this).attr('src');
				var newSrc = oldSrc.replace('b5202a', '7f7f99');
				$(this).attr('src', newSrc);
			}
	);
	
	//higlight active item
	var oldSrc = $("#mainMenu ul li.active a span img").attr('src');
	if(oldSrc){
		var newSrc = oldSrc.replace('7f7f99', 'b5202a');
	}
	
	$("#mainMenu ul li.active a span img").attr('src', newSrc);
	
	//fix normal H1 behavior for right coll
	
	$.each( $("#rightCol h1"), function(i, n){
		if( !$(this).children().is('a') ){
			//alert('B');
			$(this).addClass('noLinkHeader');
		}
	});
	
	if($('#carousel').length > 0){
	 //play movie on click
	  $("#testimonials #carousel ul li a").click(function(){
	  	var aLink = $(this).attr('href');
	  	playVideoJs(aLink);
	  	return false;
	  });
	} 
	
	if($('#nocarousel').length > 0){
	 	  
	  //play movie on click
	  $("#testimonials #nocarousel ul li a").click(function(){
	  	aLink = $(this).attr('href');
	  	playVideoJs(aLink);
	  	return false;
	  });
	} 
	
	
	$("li.thumbGal").each(function(){
		h1 = $(this).height();
		$img = $(this).children().children();
		h2 = $img.height();
		h = h1-h2;
		$img.css("padding-top",(h/2)-5);
	})
	
	/*add submenus - javascript is easier to use*/
	
	if($('#sidemenu li.active a[title="Representative Opportunities"]').length > 0){
		
		link = "http://international.humber.ca/contact-us/representative-opportunities/prospective-representative-questionnaire";
		loc = window.location;
		if(loc != link){
			$('#sidemenu li.active').append('<a href="'+link+'" class="subMenuJs" alt="' + window.location + '"> &raquo; Questionnaire</a>');
		}else{
			$('#sidemenu li.active').append('<a href="'+link+'" class="subMenuJsActive"> &raquo; Questionnaire</a>');
		}
	}
	
	if($('#sidemenu li.active a[title="Alumni"]').length > 0){
		
		link = "http://international.humber.ca/student-services/alumni/international-alumni-application-form";
		loc = window.location;
		if(loc != link){
			$('#sidemenu li.active').append('<a href="'+link+'" class="subMenuJs" alt="' + window.location + '"> &raquo; Application Form</a>');
		}else{
			$('#sidemenu li.active').append('<a href="'+link+'" class="subMenuJsActive"> &raquo; Questionnaire</a>');
		}
	}
	
	
});


function thisMovie(movieName) {
     if (navigator.appName.indexOf("Microsoft") != -1) {
         return window[movieName];
     } else {
         return document[movieName];
     }
 }
function playVideoJs(url) {
 thisMovie("video").playVideo(url);
}
