//SET NOCONFLICT TO WORK WITH OTHER LIBRARIES
jQuery.noConflict();

//CUSTOM JQUERY FUNCTIONS
jQuery(document).ready(function(){

	jQuery("#contactForm").slideLock();

	jQuery(window).load(function() {
	    jQuery('#slider').nivoSlider({
	        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
	        slices:1, // For slice animations
	        boxCols: 8, // For box animations
	        boxRows: 4, // For box animations
	        animSpeed:500, // Slide transition speed
	        pauseTime:3000, // How long each slide will show
	        startSlide:0, // Set starting Slide (0 index)
	        directionNav:true, // Next & Prev navigation
	        directionNavHide:false, // Only show on hover
	        controlNav:false, // 1,2,3... navigation
	        controlNavThumbs:false, // Use thumbnails for Control Nav
	        controlNavThumbsFromRel:false, // Use image rel for thumbs
	        controlNavThumbsSearch: '.jpg', // Replace this with...
	        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
	        keyboardNav:true, // Use left & right arrows
	        pauseOnHover:true, // Stop animation while hovering
	        manualAdvance:false, // Force manual transitions
	        captionOpacity:1, // Universal caption opacity
	        prevText: 'Prev', // Prev directionNav text
	        nextText: 'Next', // Next directionNav text
	        beforeChange: function(){}, // Triggers before a slide transition
	        afterChange: function(){}, // Triggers after a slide transition
	        slideshowEnd: function(){}, // Triggers after all slides have been shown
	        lastSlide: function(){}, // Triggers when last slide is shown
	        afterLoad: function(){} // Triggers when slider has loaded
	    });
	});
		
	//Check if element exists
	if (jQuery('#mycarousel').length != 0){
		
		// Initialize the carousel
		jQuery("#mycarousel").jcarousel({
			scroll: 1,
			auto: 6,
			wrap: 'circular'
		});
		
	
	}
	
	// Enable the dropdowns
	jQuery('ul#nav').superfish({
		 autoArrows: false,
		 dropShadows: false
	});
	
	//Style the sitemap
	jQuery('ul#siteMap li:has(ul)').addClass('parent');
	
	if (jQuery.cookie('lang') != "1")
	{
		//Show the splash page
		jQuery.blockUI({ message: jQuery('#splash'), css: { width: '549px' } });
	}
	
});

//Initialize the carousel for the homepage
function mycarousel_initCallback(carousel) {
	
	jQuery('.jcarousel-control a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		return false;
	});
	
	jQuery('#mycarousel-next').bind('click', function() {
		carousel.next();
		return false;
	});
	
	jQuery('#mycarousel-prev').bind('click', function() {
		carousel.prev();
		return false;
	});
	 
	// Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
	
};

//Set the language cookie
function setLanguage(lang, currentLang){
		
	jQuery.cookie('lang', "1", { expires: 365, path: '/'});
	
	if (lang == currentLang)
	{
		//en or fr 
		jQuery.unblockUI();
	}
	else
	{
		window.location = "/" + lang + "/";
	}
}

//clearInput function
jQuery.fn.clearInput = function(){
	return this.focus(function(){
		if(this.value == this.defaultValue){
			this.value = "";
		}
	}).blur(function(){
		if(!this.value.length){
			this.value = this.defaultValue;
		}
	});
};

//clearForm function
jQuery.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return jQuery(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};
