//----------------------------------------------------------------------------------------

// Authors : Guillaume Quimper & Nadia HADJI, Influenza marketing http://www.influenza.ca
// Version 1.0
// Created: April 2011

//----------------------------------------------------------------------------------------


//------------------------------------------------------------------------
// Font Replacement - Cufon
//------------------------------------------------------------------------
 
Cufon.set('fontFamily', 'CCSpills');
Cufon.replace('#mainContent h1, #interact h5, #newsletter h1, #message h1');

/*Cufon.set('fontFamily', 'GarageGot_shadow');
Cufon.replace('#subNav h3');*/

Cufon.set('fontFamily', 'GarageGot');
Cufon.replace('#subNav h3, .menuDetails h2, .intranet h2, #contact h3, #feedback h3, #applyForm h3, #welcomeMessage h3');

//------------------------------------------------------------------------
// Homepage Caroussel
//------------------------------------------------------------------------

$(function(){
	$('#slider').cycle({ 
		slideExpr: '.slide',
		fx: 'scrollHorz',
		cleartypeNoBg: true,
		cleartype:  1,
		pager: '#pager',
		pause: true,
    	pauseOnPagerHover: true, 
		speed:   300, 
    	timeout: 7000
	});
});

//------------------------------------------------------------------------
// Watermark Labels
//------------------------------------------------------------------------

$(function(){
	$("input.textInput").focus(function() {
		$(this).prev("label.watermark").fadeOut('fast');											  
	});
	
	$("input.textInput").blur(function() {
		var inputValue  = $(this).val();
		if (inputValue == "") {
			$(this).prev("label.watermark").fadeIn('fast');
		}
	});
});

//------------------------------------------------------------------------
// Content Styling
//------------------------------------------------------------------------

$(function(){
	$("#content h5 ~ p").css("padding-top", 4);
});

//------------------------------------------------------------------------
// Footer Styling
//------------------------------------------------------------------------

$(function(){
	$("#interact li.normal a").append(" &raquo;");
});


//------------------------------------------------------------------------
// Item Equal Heigth Boxes
//------------------------------------------------------------------------

$(function(){
	var biggestHeight = 0;
	$('.item').each(function(){
		if($(this).height() > biggestHeight){
			biggestHeight = $(this).height();
		}
	});
	$('.item').height(biggestHeight);
});

//------------------------------------------------------------------------
// Open Google Map Itinerary
//------------------------------------------------------------------------


function googleItinary() {
	var goTo = $('#toAddress').val();
	var goFrom = $('#fromAddress').val();
	var lang = $('#itineraryLang').val();
	var googleURL = "http://maps.google.ca/maps?hl=" + lang + "&saddr=" + goFrom + "&daddr=" + goTo;
	window.open(googleURL, "_blank");
    return false;
}

$(function(){	
	$("#getItinerary").click(function() {
		googleItinary();							  
	});
	$("#getItinararyForm").submit(function() {
		googleItinary();							  
	});
});


//------------------------------------------------------------------------
// Menu Page - Initiate Coda-Slide 2.0
//------------------------------------------------------------------------

$(function(){
     $('#coda-slider-1').codaSlider({
         dynamicArrows: false,
         dynamicTabs: false  /*Disabled to give us more control over CSS */

     });
});


//------------------------------------------------------------------------
// Nutritional Facts Page - Initiate jQuery UI Accordeons
//------------------------------------------------------------------------

$(function(){
	$( "#accordeons" ).accordion({
		collapsible: true,
		active: false,
		clearStyle: true,
		autoHeight: false
	});
});

//------------------------------------------------------------------------
// Date Picker Form
//------------------------------------------------------------------------

$(function() {
  $('.datepicker').datepicker({display: 'inline', dateFormat: 'dd-mm-yy'});
});


//------------------------------------------------------------------------
// Current page Item link Info Nutri Detail sidebar
//------------------------------------------------------------------------

$(function() {
  $('.infonutri #subNav ul li.page-item-48').addClass('current_page_item');
  $('.infonutri #subNav ul li.page-item-435').addClass('current_page_item');
  $('.concours #subNav ul li.page-item-8').addClass('current_page_item');
  $('.single #subNav ul li.page-item-15').addClass('current_page_item');
  $('.menu-intranet #subNav ul li.page-item-288').addClass('current_page_item');
  $('.post:first').addClass('first');
});


//------------------------------------------------------------------------
// Mailto Links Protection
//------------------------------------------------------------------------

jQuery.fn.mailto = function() {
	return this.each(function(){
		var email = $(this).html().replace(/\s*\(.+\)\s*/, "@");
		$(this).before('<a href="mailto:' + email + '" rel="nofollow" class="email" title="Email ' + email + '" onclick="javascript: _gaq.push([\'_trackEvent\', \'Email\', \'clics\', \'' + email + '\']);" >' + email + '</a>').remove();
	});
};

$(function() {
	$('a.email').mailto();
});

//------------------------------------------------------------------------
// Promos Caroussel
//------------------------------------------------------------------------


$(function(){
	$('#promoContainer').cycle({ 
		slideExpr: 'div.slide',
		fx: 'scrollHorz',
		cleartypeNoBg: true,
		cleartype:  1,
		pager: '#pager',
		next: '#next',
		prev: '#prev',
    	pauseOnPagerHover: true, 
		speed:   300, 
    	timeout: 7000
	});
});


//------------------------------------------------------------------------
// Custom Modal Window
//------------------------------------------------------------------------
  
$(function(){
	$('a[rel="modal"]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width  
        var maskHeight = $(document).height();  
        var maskWidth = $(window).width();  
       
        //Set height and width to mask to fill up the whole screen  
        $('#mask').css({'width':maskWidth,'height':maskHeight});  
           
        //transition effect      
        $('#mask').fadeTo("fast", 0.8);    
       
        //Get the window height and width  
        var winH = $(window).height();  
        var winW = $(window).width();  
                 
        //Set the popup window to center  
        $(id).css('top',  winH/2-$(id).height()/2);  
        $(id).css('left', winW/2-$(id).width()/2); 
    
    	//transition effect
    	$(id).fadeIn(700);
    });
    
    //Adjust Mask on Window Resize
	$(window).resize(function() {
		//Get the screen height and width  
		var maskHeight2 = $(document).height();  
        var maskWidth2 = $(window).width();
		$('#mask').css({'width':maskWidth2,'height':maskHeight2});   
	 });

     //if close button is clicked  
     $('.modalWindow .close').click(function() {
         $('#mask').fadeOut();
         $('.modalWindow').fadeOut();
         return false;
     });

     //if mask is clicked  
     $('#mask').click(function() {
         $(this).fadeOut();
         $('.modalWindow').fadeOut();
     });
});

//------------------------------------------------------------------------
// Intranet View Candidate
//------------------------------------------------------------------------

$(function() {
  $('#applyForm.intranet input').attr('disabled', 'disabled');
  $('#applyForm.intranet input').addClass('viewData');
});


//------------------------------------------------------------------------
// Gift Certificate Fucntions
//------------------------------------------------------------------------

$(function() {
	$('input[name|="shippingOption"]').change(function(){
		var shippingOption = $('input[name|="shippingOption"]:checked').val();
		//console.log(shippingOption);
		if (shippingOption == '1' || shippingOption == '2') {
			$('#pickupForm').hide();
			$('#paypalForm').show();
			if(shippingOption == '2') $('#shipping').val('15.00')
		}
		if (shippingOption == '3') {
			$('#pickupForm').show();
			$('#paypalForm').hide();
		}
	});

});
