jQuery(document).ready(function() {
	

	jQuery('div.typography, div#homePagePictures').fadeIn(2000);

	//this.tooltip = function(){	
		/* CONFIG */		
			xOffset = 10;
			yOffset = 20;		
			// these 2 variable determine popup's distance from the cursor
			// you might want to adjust to get the right result		
		/* END CONFIG */		
		jQuery("a.tooltip").hover(function(e){											  
			this.t = this.title;
			this.title = "";									  
			jQuery("body").append("<p id='tooltip'>"+ this.t +"</p>");
			jQuery("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");		
		},
		function(){
			this.title = this.t;		
			jQuery("#tooltip").remove();
		});	
		jQuery("a.tooltip").mousemove(function(e){
			jQuery("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px");
		});			
	//};



	//tooltip();


	var modelLink = 0;
	jQuery('#modelLink').click(function() { 
		if (modelLink == 0)
		{
			jQuery('#modelsNaviBlock').animate({
				top: '-=130'
			}, 700);
			modelLink = 1;
		} else {
			jQuery('#modelsNaviBlock').animate({
				top: '+=130'
			});

			modelLink = 0;
		}
	});

	jQuery('.allModels a').click(function () {
		if (modelLink == 0)
		{
			jQuery('#modelsNaviBlock').animate({
				top: '-=130'
			}, 700);
			modelLink = 1;
		} else {
			jQuery('#modelsNaviBlock').animate({
				top: '+=130'
			});

			modelLink = 0;
		}
	});
	
	if (jQuery('div#homePagePictures').length>0)
	{
	
		jQuery('div#homePagePictures') 
		.cycle({ 
			fx:     'scrollHorz', 
			speed:  700, 
			timeout: 7000,
			ease: 'easeInOutCubic', 
			next:   '#nextImage', 
			prev:   '#prevImage' 
		});

		jQuery('div#homePagePictures').cycle('pause');


		jQuery('#nextImage').mouseover(function () {
			jQuery('#nextImage').animate({opacity: 0.9});
		}).mouseout(function () {
			jQuery('#nextImage').animate({opacity: 0.02});
		});

		jQuery('#prevImage').mouseover(function () {
			jQuery('#prevImage').animate({opacity: 0.9});
		}).mouseout(function () {
			jQuery('#prevImage').animate({opacity: 0.02});
		});


		var pauseMe = 1;
		jQuery('#pauseImage').mouseover(function () {
			jQuery('#pauseImage').animate({opacity: 0.9});
		}).mouseout(function () {
			if (pauseMe == 0) {
				jQuery('#pauseImage').animate({opacity: 0.02});
			}
			
		}).click(function () {
			if (pauseMe == 0) {
				jQuery('div#homePagePictures').cycle('pause');
				pauseMe = 1;

				jQuery(this).css("background-position", "left bottom");
			} else {
				jQuery('div#homePagePictures').cycle('resume');
				pauseMe = 0;

				jQuery(this).css("background-position", "left top");
			}
			
		});

	}


	if (jQuery('div.modelPic').length>0)
	{
	
		jQuery('div.modelPic') 
		.cycle({ 
			fx:     'scrollHorz', 
			speed:  700, 
			timeout: 7000,
			pager: '#modelPicNav',
			ease: 'easeInOutCubic', 
			next:   '#nextImage', 
			prev:   '#prevImage'
		});

		jQuery('div.modelPic').cycle('pause');


		jQuery('#nextImage').mouseover(function () {
			jQuery('#nextImage').animate({opacity: 0.9});
		}).mouseout(function () {
			jQuery('#nextImage').animate({opacity: 0.02});
		});

		jQuery('#prevImage').mouseover(function () {
			jQuery('#prevImage').animate({opacity: 0.9});
		}).mouseout(function () {
			jQuery('#prevImage').animate({opacity: 0.02});
		});
		

		var pauseMe = 1;
		jQuery('#pauseImage').mouseover(function () {
			jQuery('#pauseImage').animate({opacity: 0.9});
		}).mouseout(function () {
			if (pauseMe == 0) {
				jQuery('#pauseImage').animate({opacity: 0.02});
			}
		}).click(function () {
			if (pauseMe == 0) {
				jQuery('div.modelPic').cycle('pause');
				pauseMe = 1;

				jQuery(this).css("background-position", "left bottom");
			} else {
				jQuery('div.modelPic').cycle('resume');
				pauseMe = 0;

				jQuery(this).css("background-position", "left top");
			}
			
		});

		

	}



	jQuery("div.navigation ul#mainNav li").mouseover(function() {
		
		var poss = jQuery(this).position();
		
		if ( jQuery.browser.msie ) {
			
		 } else {
			jQuery("div.navigation ul#mainNav").stop().animate({backgroundPosition:poss.left+"px 0px"}, 1000);
		 }

		
	}).mouseleave(function() {
		
		if (jQuery("li.current_page_item").length>0) {
	
			var currentMenuItemPos = jQuery("li.current_page_item").position();

			if ( jQuery.browser.msie ) {
				
			 } else {
				jQuery("div.navigation ul#mainNav").stop().animate({backgroundPosition:currentMenuItemPos.left+"px 0px"}, 1000);
			 }

		} else {
			if ( jQuery.browser.msie ) {
				
			 } else {
				jQuery("div.navigation ul#mainNav").stop().animate({backgroundPosition:"-100px 0px"}, 1000);
			 }
		}

		
	});
	
	if (jQuery("li.current_page_item").length>0) {
	
		var currentMenuItemPos = jQuery("li.current_page_item").position();
		if ( jQuery.browser.msie ) {
			
		 } else {
			jQuery("div.navigation ul#mainNav").animate({backgroundPosition:currentMenuItemPos.left+"px 0px"}, 1000);

			jQuery("div.navigation ul#mainNav").css({backgroundPosition:currentMenuItemPos.left+"px 0px"});
		 }


	}

	if (jQuery("ul.productMenu li").length>0) {
		jQuery("ul.productMenu li").each(function(index) {
			jQuery(this).delay(index*100).fadeIn(500);
		});
	}

	if (jQuery("div.navigation ul#mainNav li ul.subPopup").length>0) {
		jQuery("div.navigation ul#mainNav li ul.subPopup").each(function(index) {
			var myHeight = jQuery(this).height() + 36;
			//jQuery(this).css("margin-top","-"+myHeight+"px");
		});
	}
	
	jQuery("div.navigation ul#mainNav li ul.subPopup").css("height", "0px");

	if (jQuery('#specLink').length>0) {
		var specLink = 0;
		jQuery('#specLink').click(function() {
			if (specLink == 0) {
				specLink = 1;
				jQuery('.typography .myContent').animate({marginLeft:'492px'}, 500);
			} else {
				specLink = 0;
				jQuery('.typography .myContent').animate({marginLeft:'847px'}, 500);
			}
		});
	}

	Cufon.replace('.productMenu', {hover:{color:'#ffffff'}});
	Cufon.replace('.navigation ul li a');
	Cufon.replace('.modelPicNavigation');
	Cufon.replace('.typography h2');
	Cufon.replace('div.rightContent');
	Cufon.replace('div.leftContent');
	Cufon.replace('span#modelPicNav a');
	Cufon.replace('.typography .myContent');

});

function showSubPopup(id) {
	var myHeight = jQuery("#subPopup_"+id +" li").length;
	//alert(myHeight+"<---");
	myHeight = myHeight*36;

	var myMargin = myHeight + 36;
	jQuery('#subPopup_'+id).stop().animate({height:myHeight+'px', marginTop:"-"+myMargin+"px"}, 1000);
}

function hideSubPopup(id) {
	jQuery('#subPopup_'+id).stop().animate({height:'0px', marginTop:"-36px"}, 500);
}
