/*
 * jQuery 1.2.6 - New Wave Javascript
 *
 * Copyright (c) 2008 John Resig (jquery.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * jQueryDate: 2008-05-24 14:22:17 -0400 (Sat, 24 May 2008) jQuery
 * jQueryRev: 5685 jQuery
 */

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	 
	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );	 	 
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+jQuery/g, '');
	 
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
		  // we need to handle case where cookie has no value but exists (no = sign, that is):
		  if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+jQuery/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}

(function(jQuery) {
  var peekaBooTimer = null;
  var whichImgActive = 1;
  function peekaBooHide() {
		jQuery("#product_addtocart_showhide").slideUp(500);
		jQuery("#productDetail-purchase-header img").fadeOut(200);
		jQuery("#btn-expandPurchase").fadeIn(500);
		jQuery("#btn-addToBag").css("margin-top","0");
		clearTimeout(peekaBooTimer);
	}
 
  function peekaBoo() {
	  if(!getCookie('peek')) {
			setCookie('peek',1);
		} else {
			setCookie('peek',(getCookie('peek')*1) + 1);
		}
		if(getCookie('peek') <= 3) {
			jQuery("#btn-addToBag").css("margin-top","44px");
			jQuery("#btn-expandPurchase").css("display","none");
			jQuery(".bn-button").css("display","block");
			if ( jQuery.browser.msie && (jQuery.browser.version < 7) ) {
				jQuery("#productDetail-purchase-header img").show();
				jQuery("#product_addtocart_showhide").show();
			} else {
				jQuery("#productDetail-purchase-header img").fadeIn(200);
				jQuery("#product_addtocart_showhide").slideDown(500);
			}
			clearTimeout(peekaBooTimer);
			peekaBooTimer = setTimeout(function(){peekaBooHide();},2500);
		}
	}
 
	jQuery(document).ready(function(){
		jQuery(".anchor-scroll").click(function(event){
			//prevent the default action for the click event
			event.preventDefault();
			//get the full url - like mysitecom/index.htm#home
			var full_url = this.href;
			//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
			var parts = full_url.split("#");
			var trgt = parts[1];
			//get the top offset of the target anchor
			var target_offset = jQuery("#"+trgt).offset();
			var target_top = target_offset.top-200;
			//goto that anchor by setting the body scroll top to anchor top
			//debugger
			jQuery('html, body').animate({scrollTop:target_top}, 500, null, scrollClick);
		});
	});
 
	function scrollClick(){
		jQuery('#btn-expandPurchase').trigger('click'); 
	}
 
	jQuery(document).ready(function() {
 
		//var productViewWidth = (62 * prodImages.length) + 20;
		//jQuery("#photoBox-productViews").css("width",productViewWidth + "px");
		 
		peekaBooTimer = setTimeout(function(){peekaBoo();},1500); 

		jQuery("#btn-expandPurchase").click(
			function() {
				jQuery(this).css("display","none");
				if ( jQuery.browser.msie && (jQuery.browser.version < 7) ) {
					jQuery("#productDetail-purchase-header img").show();
					jQuery("#product_addtocart_showhide").show();
				} else {
					jQuery("#productDetail-purchase-header img").fadeIn(200);
					jQuery("#product_addtocart_showhide").slideDown(250);
				}
			} 
		);
		
		jQuery("#productDetail-purchase-header img").click(
			function() {
				jQuery("#product_addtocart_showhide").slideUp(250);
				jQuery("#productDetail-purchase-header img").fadeOut(100);
				jQuery("#btn-expandPurchase").fadeIn(250);
			}
		); 
	});
});
