// fix a bug into navbar menu for IE6 

sfHover = function() {
	var sfEls = document.getElementById("navbar").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


var fullBannerVisible = false;

$(document).ready(function(){

	/*$("#programs").hide();
	$("#services").hide();
	$("#international").hide();*/
	$("#programs_left_arrow").hide();
	$("#programs_right_arrow").hide();
	$("#program_list_on").hide();

	$("#footer_map a[rel=external]").attr('target', '_blank');


/* 	$("#programs").mouseover(function() {
   		$("#programs").show();
  	}).mouseout(function(){
    	$("#programs").hide();
  	});



	$("#services").mouseover(function() {
   		$("#services").show();
  	}).mouseout(function(){
    	$("#services").hide();
  	});
*/


/* FOOTER */


	// program
	$("#footer_programs_submenu").hide();
	//$(".show_hide").show();
		 
	$("#footer_programs").click(function(){
		$("#footer_services_submenu").hide();
		$("#footer_international_submenu").hide();
		$("#footer_programs_submenu").slideToggle();
	});

	
	// service
	$("#footer_services_submenu").hide();
	//$(".show_hide").show();
		 
	$("#footer_services").click(function(){
		$("#footer_programs_submenu").hide();
		$("#footer_international_submenu").hide();
		$("#footer_services_submenu").slideToggle();
	});
	
	

	// international
	$("#footer_international_submenu").hide();
	//$(".show_hide").show();
		 
	$("#footer_international").click(function(){
		$("#footer_programs_submenu").hide();
		$("#footer_services_submenu").hide();
		$("#footer_international_submenu").slideToggle();
	});	


	// program detail page
	$("#program_list_detail").hide();
	
	$("#program_list_off").click(function(){
		$("#program_list_off").hide();
		$("#program_list_on").show();
	$("#program_list_detail").slideToggle();
	});
	


						   
    $("#messageBox").animate({top:"215px"},2500);
    $("#messageBox").delay(6000);
    $("#messageBox").animate({top:"-265px"},3500);
	$("#messageBox").hide("slow", 0);

	

	

/*******************/


    // new menu
	
	$("#internationaux li:not(:first)").hover(
	  function () {

	    $(this).find("img").css('visibility','visible')
	  }, 
	  function () {
	     $(this).find("img").css('visibility','hidden')
	  }
	);

	$("#service li:not(:first)").hover(
	  function () {

	    $(this).find("img").css('visibility','visible')
	  }, 
	  function () {
	     $(this).find("img").css('visibility','hidden')
	  }
	);

	$("#program li:not(:first)").hover(
	  function () {

	    $(this).find("img").css('visibility','visible')
	  }, 
	  function () {
	     $(this).find("img").css('visibility','hidden')
	  }
	);

	$("#college li:not(:first)").hover(
	  function () {

	    $(this).find("img").css('visibility','visible')
	  }, 
	  function () {
	     $(this).find("img").css('visibility','hidden')
	  }
	);

	

	// Form action
	// Init floating button
	$("#toggle-btn, #close-icon, #demandeinfo").click(function() {
		
		if(!fullBannerVisible) {			
			// Show
			var docWidth = $(document).width()/2-380;				
			//$("#full-banner").animate({width:'+='+docWidth, margin:'auto 0'}, 'slow');
			$("#banner").animate({right:docWidth}, 'slow');
			fullBannerVisible = true;
		} else {
			// Hide
			//$("#full-banner").animate({width:'53'}, 'slow');
			$("#contactForm").validationEngine('hideAll');
			$("#banner").animate({right:-789}, 'slow');
			fullBannerVisible = false;
		}		
	});	
	
	
	// Init Place holder	
	$('input[placeholder], textarea[placeholder]').placeholder();
	
	// Init Date picker
	var options = $.datepicker.regional[ "fr" ];
	options.showOn="button";
	options.dateFormat = 'dd/mm/yy';
	options.buttonImage = "/images/date.png";
	options.buttonImageOnly = true;
	$("input[date]").datepicker(options);

	// Init Student dialog
	/*$('#studentDlg').dialog({
		autoOpen: false,
		height: 725,
		width: 700,
		modal: true,
		resizable: false,
		draggable:false,
		open:function() {
			// Resolve scrolling problem in Chrome and Safari
			window.setTimeout(function() {$(document).unbind('mousedown.dialog-overlay').unbind('mouseup.dialog-overlay'); }, 100);			
		},	
		close:function() {
			$("#studentForm").validationEngine('hideAll');
		}	
	});

	// Init Employer dialog
	$('#employerDlg').dialog({
		autoOpen: false,
		height: 1050,
		width: 700,
		modal: true,
		resizable: false,
		draggable:false	,
		open:function() {
			// Resolve scrolling problem in Chrome and Safari
			window.setTimeout(function() {$(document).unbind('mousedown.dialog-overlay').unbind('mouseup.dialog-overlay'); }, 100);
			$('#fix').hide();
		},
		close:function() {
			$('#fix').show();
			$("#employerForm").validationEngine('hideAll');			
		}	
	});	
	*/
	
	// Form validation
	$("#contactForm").validationEngine('attach', {scroll: false});
	$("#studentForm").validationEngine('attach', {scroll: false});
	$("#employerForm").validationEngine('attach', {scroll: false});
	
	$('input:checkbox').checkbox({cls:'jquery-checkbox'});
	$('input:radio').checkbox({cls:'jquery-radiobox'});
	
	

});

/*var showStudentForm = function() {
	$("#studentDlg").dialog('open');
};

var showEmployerForm = function() {
	$("#employerDlg").dialog('open');
};
*/

var valideAmiNomPrenom = function (field, rules, i, options){
	
	if(field.attr('id') == 'inomami' && field.val() == '' && $("#iprenomami").val() != '') {
		return 'Le nom est requis!';		
	}
	
	if(field.attr('id') == 'iprenomami' && field.val() == '' && $("#inomami").val() != '') {
		return 'Le prénom est requis!';
	}
};

$(document).ready(function()
{
	$("#firstpane p.menu_head").click(function()
    {
		$(this).css({'background': '#bfc3bf url(/images/program_minus.jpg) no-repeat 8px','padding-left':'35px'}).next("div.menu_body").slideToggle(225).siblings("div.menu_body").slideUp("slow");
       	$(this).siblings().css({'background': '#1d6443 url(/images/program_plus.jpg) no-repeat  8px'});
	});
	
	
		$("#video_480x360_1, #video_480x360_2, #video_480x360_3").click(function() {
				$.fancybox({
						'padding'		: 0,
						'autoScale'		: false,
						'transitionIn'	: 'none',
						'transitionOut'	: 'none',
						'title'			: this.title,
						'width'			: 480,
						'height'		: 360,
						'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
						'type'			: 'swf',
						'swf'			: {
							 'wmode'		: 'transparent',
							'allowfullscreen'	: 'true'
						}
					});
			
				return false;
			});	
		
			

		$("#video_480x480_1, #video_480x480_2").click(function() {
				$.fancybox({
						'padding'		: 0,
						'autoScale'		: false,
						'transitionIn'	: 'none',
						'transitionOut'	: 'none',
						'title'			: this.title,
						'width'			: 480,
						'height'		: 480,
						'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
						'type'			: 'swf',
						'swf'			: {
							 'wmode'		: 'transparent',
							'allowfullscreen'	: 'true'
						}
					});
			
				return false;
			});	
			
			


	if($('.slideshow').length > 0) {
		
	    if($.browser.msie && parseInt($.browser.version, 10) <= 8) {
		    $('.slideshow').cycle({
				fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				speed:   0, 
				timeout: 4500, 
				next:   '.slideshow', 
				pause:   1,
				cleartype: true, 
				cleartypeNoBg: true  
			});			
		}
		else {
		    $('.slideshow').cycle({
				fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				speed:   3000, 
				timeout: 4500, 
				next:   '.slideshow', 
				pause:   1,
				cleartype: true, 
				cleartypeNoBg: true  
			});					
		}

	}		
	
});



