/*************************** List Styling ***************************/

jQuery(document).ready(function(){	
	jQuery("ul li:first-child").addClass("li-first");
	jQuery("ul li:last-child").addClass("li-last");		
});


/*************************** Navigation Menu ***************************/

jQuery(document).ready(function(){	

	var nav = jQuery("#nav");

	nav.find("li").each(function() {
		Cufon.replace('#nav', {hover: true});
		if (jQuery(this).find("ul").length > 0) {

			jQuery("<span/>").html("<img src='"+rootFolder+"/images/nav_arrow.png' alt=''/>").appendTo(jQuery(this).children(":first"));

			jQuery(this).mouseenter(function() {
				jQuery(this).find("ul:first").filter(':not(:animated)').slideDown(600);
			});

			jQuery(this).mouseleave(function() {
				jQuery(this).find("ul:first").slideUp(0);
			});
			
		}
	});
	
});


/*************************** Image Hover Effects ***************************/

jQuery(document).ready(function() { 

	jQuery('.circle-content-text').css({'opacity':'0'});
	jQuery('.circle').hover(
		function() {
			jQuery(this).find('.circle-content-text').stop(true,true).fadeTo(500, 0.95);
			jQuery(this).addClass('circle-active');
			jQuery(this).css("border-width","0");
		},
		function() {
			jQuery(this).find('.circle-content-text').stop(true,true).fadeTo(500, 0);
			jQuery(this).removeClass('circle-active');		
			jQuery(this).css("border-width","2px");		
		}
	);
	
	jQuery('.circle-content-image').css({'opacity':'0'});
	jQuery('.circle').hover(
		function() {
			jQuery(this).find('.circle-content-image').stop(true,true).fadeTo(800, 1);
			jQuery(this).addClass('circle-active');
			jQuery(this).css("border-width","0");
		},
		function() {
			jQuery(this).find('.circle-content-image').stop(true,true).fadeTo(800, 0);
			jQuery(this).removeClass('circle-active');		
			jQuery(this).css("border-width","2px");		
		}
	);
	
	
	jQuery("#circle1").hover(
		function() {jQuery(this).stop(true,true).animate({width:"395px",height:"395px"},500);},
		function() {jQuery(this).stop(true,true).animate({width:"395px",height:"395px"},300);}	
	);
	jQuery("#circle2,#circle17").hover(
		function() {jQuery(this).stop(true,true).animate({width:"395px",height:"335px"},500);},
		function() {jQuery(this).stop(true,true).animate({width:"126px",height:"126px"},300);}	
	);
	jQuery("#circle3,#circle16").hover(
		function() {jQuery(this).stop(true,true).animate({width:"395px",height:"335px"},500);},
		function() {jQuery(this).stop(true,true).animate({width:"62px",height:"62px"},300);}	
	);
	jQuery("#circle4,#circle15").hover(
		function() {jQuery(this).stop(true,true).animate({width:"395px",height:"335px"},500);},
		function() {jQuery(this).stop(true,true).animate({width:"79px",height:"79px"},300);}	
	);
	jQuery("#circle5,#circle14").hover(
		function() {jQuery(this).stop(true,true).animate({width:"395px",height:"335px"},500);},
		function() {jQuery(this).stop(true,true).animate({width:"88px",height:"88px"},300);}	
	);
	jQuery("#circle6,#circle13").hover(
		function() {jQuery(this).stop(true,true).animate({width:"395px",height:"335px"},500);},
		function() {jQuery(this).stop(true,true).animate({width:"70px",height:"70px"},300);}	
	);
	jQuery("#circle7,#circle12").hover(
		function() {jQuery(this).stop(true,true).animate({width:"395px",height:"335px"},500);},
		function() {jQuery(this).stop(true,true).animate({width:"56px",height:"56px"},300);}	
	);
	jQuery("#circle8,#circle11").hover(
		function() {jQuery(this).stop(true,true).animate({width:"395px",height:"335px"},500);},
		function() {jQuery(this).stop(true,true).animate({width:"84px",height:"84px"},300);}	
	);
	jQuery("#circle9,#circle10").hover(
		function() {jQuery(this).stop(true,true).animate({width:"395px",height:"335px"},500);},
		function() {jQuery(this).stop(true,true).animate({width:"42px",height:"42px"},300);}	
	);

});


/*************************** Lightbox ***************************/

jQuery(document).ready(function(){

	jQuery("div.gallery-item .gallery-icon a").attr("rel", "prettyPhoto[gallery]");
	
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'pp_default',
		animationSpeed: 'fast'
	});

});


/*************************** Toggle Content ***************************/

jQuery(document).ready(function(){	

	jQuery(".toggle-box").hide(); 
	
	jQuery(".toggle").toggle(function(){
		jQuery(this).addClass("toggle-active");
		}, function () {
		jQuery(this).removeClass("toggle-active");
	});
	
	jQuery(".toggle").click(function(){
		jQuery(this).next(".toggle-box").slideToggle();
	});

});


/*************************** Contact Form ***************************/

jQuery(document).ready(function(){
	
	jQuery('#contact-form').submit(function() {

		jQuery('.contact-error').remove();
		var hasError = false;
		jQuery('.requiredFieldContact').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				jQuery(this).addClass('input-error');
				hasError = true;
			} else if(jQuery(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
					jQuery(this).addClass('input-error');
					hasError = true;
				}
			}
		});
	
	});
				
	jQuery('#contact-form .contact-submit').click(function() {
		jQuery('.loader').css({display:"block"});
	});	

});


/*************************** Image Preloader ***************************/

jQuery(function () {
	jQuery('.preload').hide();//hide all the images on the page
});

var i = 0;//initialize
var int=0;//Internet Explorer Fix
jQuery(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
	var int = setInterval("doThis(i)",10);//500 is the fade in speed in milliseconds
});

function doThis() {
	var images = jQuery('.preload').length;//count the number of images on the page
	if (i >= images) {// Loop the images
		clearInterval(int);//When it reaches the last image the loop ends
	}
	jQuery('.preload:hidden').eq(0).fadeIn(500);//fades in the hidden images one by one
	i++;//add 1 to the count
}
