/**
 * @author eli geske
 */

 $(document).ready(function(){

	// get current base url
	$currPage =	window.location.pathname;
	$currPage = $currPage.substring($currPage.lastIndexOf('/') + 1);

	if ( $.browser.msie ) {
	  $iev = $.browser.version;	  
	  $('#spotted_text>div').css('margin-top','-85px');
	  
	}
	
	// letter products selection validation
	$('form').submit(function(){
		$error = false;
		$selectVal = new Array();
		$i = 0;
		$('option').each(function(){
			$text = $(this).text();
			if($text.indexOf('Select') > 0){
				$selectVal[$i] = $(this).val();
				$i++;
			}			
		});		
		
		var selects = $('select');
		$cnt = selects.length - 1;
		
		while($cnt >= 0){
			$i = $selectVal.length - 1;
			$val = selects.eq($cnt).val();
			//alert($val);
			while($i >= 0){
				if($val == $selectVal[$i])
				{
					$error = true;
				}
				$i--;
			}	
			$cnt--;
		}
		
		if($error){			
			alert('Please choose an option from each selection.');
			return false;
		}
	});
	
	// Dropdown menu
//	$('#top_menu a').mouseover(function(){
//			$('#submenu').stop();
//			$('#submenu').css('opacity', "");
//			if ($(this).html() == "shop") {
//				
//					$('#submenu').show();	
//										
//			}
//		});
//		$('#submenu').hover(function(){
//				$('#submenu').show();
//			}, function(){
//				$('#submenu').fadeOut();			
//		});
//		$('.left_body').mouseover(function(){
//			$('#submenu').fadeOut();
//		});
//		function hideMenu(){
//			$('#submenu').fadeOut();			
//		}
//	
//	
//	// color change, excluding home
//	if($currPage != "" && $currPage != "index.html"){
//				
//		function color1(){
//			$('#mid_cont').animate({backgroundColor:"jz_gold"}, 750);
//			setTimeout(color2, 15000);
//		}
//		
//		function color2(){
//			$('#mid_cont').animate({backgroundColor:"jz_pink"}, 750);
//			setTimeout(color1, 15000);		
//		}
//		color2();
//	}
//	
//		// main image rotate
	if($currPage == "" || $currPage == "index.html")
	{
		$('#home_image_2').hide();
		
		function image1(){
			$('#home_image_2').fadeOut(1500);		
			
			setTimeout(image2, 15000);
		}
		function image2(){
			$('#home_image_2').fadeIn(1500);
			setTimeout(image1, 15000);
		}
		setTimeout(image2, 15000);
	}

	// carousel page load - spotted.html
	
	// CLICK AND LOAD
	$('#spotted_carousel img').live('click',function(){
		
		$('#spotted_text div').remove();
		$('#spotted_text p').remove();
		$html =	$(this).next('div').html();
		$currHtml = $('#spotted_text').html();
		$('#spotted_text').html($currHtml + $html);	
		$('#spotted_text div').hide();
		$('#spotted_text p').hide();
		
		if ( $.browser.msie ) {
	  		$iev = $.browser.version;
			$('#spotted_text>div').css('margin-top','-85px');
		}
		$('#spotted_text div').fadeIn();
		$('#spotted_text p').fadeIn();

	});
	
	// UL FOR SLIDER
	
	$('#spotted_carousel ul').css({'left':'0', 'overflow': 'hidden', 'position' : 'relative'});

	$('#jz_prev').click(function(){ });
								 
	// SLIDER FUNCTIONS - NEXT 
	$('#jz_next').click(function(){		
		$('#spotted_carousel ul').animate({'left':'-688'}, 400, "linear",rotateLi);		
	});
	
	// SLIDER FUNCTIONS - PREV 
	$('#jz_prev').click(function(){
		
		// slide right
		rotateLiPrev();
		$('#spotted_carousel ul').css('left','-688px');
		$('#spotted_carousel ul').animate({'left':'0'}, 400);

		
	});
	
	
	/*function fadeInDelay(){
			$('#spotted_carousel li').fadeIn(300);
		}*/

	
	// LOGO FOLLOW
	
//	$rightHeight = $('#left_col').height();
	//alert($rightHeight);
//	if($rightHeight > 523){
//		
//		$winHeight = $winHeight = $(window).height();		
//		
		// window resize event
//		function resizeWindow(e){
//			$winHeight = $(window).height();
//			posLogo($winHeight, $rightHeight);		
//		}
		
//		function posLogo($winHeight, $rightHeight){	
//			$topHeight = $('#header').height();	
//			$scrollHeight = $(window).scrollTop();
//			$logoHeight	 = $('#logo_jz').height();
//			$logoHeight	 = $logoHeight / 2;
//			if($scrollHeight == 0){
//				$rightHeight = $('#left_col').height();
//				if($rightHeight > $winHeight){
//					$rightHeight = $winHeight + $topHeight;
//				}				
//				$margin = $rightHeight / 2;
//				$margin = $margin - $logoHeight - $topHeight;
//				$margin = Math.floor($margin);
//				$margin = $margin - 12;			
//			}else{
//				
//				if($scrollHeight < $topHeight){
//					$topHeight 	  = $scrollHeight - $topHeight;
//					$scrollHeight = 0;
//				}
//				$margin = $winHeight / 2;	
//				$margin = $margin - $logoHeight;
//				$margin = $margin + $scrollHeight - $topHeight;
//				$margin = Math.floor($margin);
//				$margin = $margin - 12;	 
//			}
//			
//			$('#logo_jz').animate({marginTop: $margin + "px"}, {queue: false, duration: 700});
//			
//		}
//		
//		posLogo($winHeight, $rightHeight);
//		
//		$(window).bind('resize', resizeWindow);
//		
//		$(window).scroll(function(){
//			posLogo($winHeight, $rightHeight);
//		});
//	}
});
function rotateLi(){
	$('#spotted_carousel li:last').after($('#spotted_carousel li:first, #spotted_carousel li:first + li,#spotted_carousel li:first + li + li,#spotted_carousel li:first + li + li + li'));
	$('#spotted_carousel ul').css({ 'left':'0' });
}
function rotateLiPrev(){
	$('#spotted_carousel li:first').before($('#spotted_carousel li:last'));
	$('#spotted_carousel li:first').before($('#spotted_carousel li:last'));
	$('#spotted_carousel li:first').before($('#spotted_carousel li:last'));
	$('#spotted_carousel li:first').before($('#spotted_carousel li:last'));
}		
		
		
		
		
		
		
$('document').ready(function(){
	  	$('.jz_buyNow').click(function(){
	  	
	  		$(this).parents('form').submit();
	  	});
 });

	$(document).ready(function(){
				
				// remove shadowbox
				$('#jz_overlay, #jz_popImg').live('click',function(){
					//$('#jz_overlay, #jz_popImg').hide(function(){
						$('#jz_overlay, #jz_popImg').remove();
					//});					
				});
				
				
				
				// spotted shadowbox
				$("#spotted_text div img").live('click',function(){
					
					$('#jz_overlay').remove();
					$winHeight 	= $(window).height();
					$winWidth	= $(window).width();
					$imgURL	= $(this).attr('src');
					$imgURL = $imgURL.replace("normal","big");
					jz_overlay($winHeight, $winWidth);
					jz_image($winHeight, $winWidth, $imgURL, false);
					return false;
				});				
				
				
				
				// product shadowbox	
				$("[rel='jz_pop']").click(function(){
					
					$('#jz_overlay').remove();
					$winHeight 	= $(window).height();
					$winWidth	= $(window).width();
					$imgURL	= $(this).attr('href');
					jz_overlay($winHeight, $winWidth);
					jz_image($winHeight, $winWidth, $imgURL, false);
					return false;
				});
				
				// window resize event
				
				$(window).unbind("resize", resizeWindow);
				$(window).bind("resize", resizeWindow);

				
				function resizeWindow(e){
					if($('#jz_overlay').length == 0){$imgtrue = false;}else{$imgtrue = true;}
					
					if($imgtrue){
						$winWidth 	= $(window).width();
						$winHeight 	= $(window).height();
						$imgURL = "";
						jz_image($winHeight, $winWidth, $imgURL, true);
						$('#jz_overlay').stop().animate({
							"height" : $winHeight,
							"width"  : $winWidth
						},{ duration: "fast"});

					}											
				}

				function imageMargin()
				{
					
					$imgHeight 	= $winHeight - 100;
					$imgWidth	= $winWidth - 100;
					$margintop  = ($winHeight - $imgHeight)/2;
					$marginleft = ($winWidth - $('#jz_popImg').width())/2;
					if($margintop  < 50){ $margintop  = 50; }
					if($marginleft < 50){ $marginleft = 50; }
					$('#jz_popImg').css({'margin-top' : $margintop,'margin-left' : $marginleft});
					$('#jz_popImg').fadeIn();	
				}
				
				function imageMargin2()
				{
					
					$imgHeight 	= $winHeight - 100;
					$imgWidth	= $winWidth - 100;
					$margintop  = ($winHeight - $imgHeight)/2;
					$marginleft = ($winWidth - $('#jz_popImg').width())/2;
					if($margintop  < 50){ $margintop  = 50; }
					if($marginleft < 50){ $marginleft = 50; }
					$('#jz_popImg').css({'margin-top' : $margintop,'margin-left' : $marginleft});	
				}
				
				function jz_overlay($winHeight, $winWidth)
				{				
					$overlayDiv = '<div id="jz_overlay" style="display: none;cursor: pointer;  background-color: rgb(0, 0, 0); opacity: 0.8; filter: alpha(opacity=80); z-index: 1000; position: fixed; top: 0; left: 0; height:'+$winHeight+'px; width:'+$winWidth+'px;" >'
					$overlayDiv += '&nbsp;</div>';
					
					$("body").prepend($overlayDiv);
					$('#jz_overlay').fadeIn();
				}
				
				function jz_image($winHeight, $winWidth, $imgURL, $resize)
				{	
					$imgHeight 	= $winHeight - 100;
					$imgWidth	= $winWidth - 100;
					
					if($imgHeight < 200){ $imgHeight = 202; }
					if($imgWidth < 200){ $imgWidth = 205; }
					if($('#jz_popImg').length == 0){
						$prodImg = "<img id='jz_popImg' align='center' style='display: none;cursor: pointer; z-index: 9999; position: fixed;' src='"+$imgURL+"' />";
						$("body").prepend($prodImg);
					}				
					
					if($resize){
						if($winHeight < $winWidth){
							$('#jz_popImg').removeAttr('width');
							$('#jz_popImg').css({'width' : ''});
							$('#jz_popImg').css({'height': $imgHeight});
						}else{
							$('#jz_popImg').removeAttr('height');
							$('#jz_popImg').css({'height' : ''});
							$('#jz_popImg').css({'width' : $imgWidth});
						}
						imageMargin2();
					}else{
						if($winHeight < $winWidth){
							$('#jz_popImg').css({'height': $imgHeight,'width': ''});
						}else{
							$('#jz_popImg').css({'width': $imgWidth,'height': ''});
						}
						setTimeout(imageMargin, 800);
												
					}	
							
				}					
				
			});


