function callFlashPlayer(){
	$(document).ready(function(){
		if(document.getElementById('homeFlashBanner')!=null){	
		getFlashPlayer();
		}
	});
}

function loadBundlePage() {
	var browseLengthValue = document.getElementById("browseLength").value;
		 var test = new Array();
	if(browseLengthValue==3){		
		var spotlight = new Array(new sldata(153,153,-66,32,98), new sldata(222,239,28,0,100), new sldata(153,153,170,32,99));	
		setTimeout( function() {
			$("body").attr("id","bundleSelect3product");
		}, 2000 );
	}
		else{
			var spotlight = new Array(new sldata(153,153,-65,32,97), new sldata(222,239,-27,0,100), new sldata(153,153,125,32,99), new sldata(68,68,245,64,98));
			var width = 1; 
			var height= 1;
			var left = 40;
			var top = 40;
			var zind = 96;
			for (var i = 4; i < browseLengthValue; i++) 
				{
				w = width;
				h = height;
				l = left;
				t = top;
				zind = zind-1;
				test[i-4] = new sldata(w,h,l,t,zind);
				spotlight.push(test[i-4]);
			}	
		}
	return spotlight;
}

function showPreCanned(){
	$(document).ready(function(){
		// Change the image of hoverable images
		$(".imgHoverable").hover( function() {
		var hoverImg = HoverImgOf($(this).attr("src"));
		$(this).attr("src", hoverImg);
		}, function() {
		var normalImg = NormalImgOf($(this).attr("src"));
		$(this).attr("src", normalImg);
		}
		);
		});
		function HoverImgOf(filename)
		{
		var re = new RegExp("(.+)\\.(gif|png|jpg)", "g");
		return filename.replace(re, "$1_hover.$2");
		}
		function NormalImgOf(filename)
		{
		var re = new RegExp("(.+)_hover\\.(gif|png|jpg)", "g");
		return filename.replace(re, "$1.$2");
	}
}

function sldata(w,h,l,t,z) { 
	this.w=w; this.h=h; this.l=l; this.t=t; this.z=z; 
	}

function submitBundlesForm(){	
	var flag="false";
	$("ul.grid li").each(function(index){
		if ($(this).hasClass("selected")){
			flag="true";
			cardSelected = index; 
			var anchorValue = $(this).find("#selected_bundleid1").val();
			document.getElementById("dwfrm_bundlesForm_bundleid").value = anchorValue;
			document.getElementById("dwfrm_bundlesForm").submit();
			return false;
		}
	});
	if(flag=="false"){
		$("ul.rotator_info li p.prod_name a").each(function(index){
			if ($(this).hasClass("selected")){
				cardSelected = index; 
				var anchorValue = $(this).find("#selected_bundleid").val();
				document.getElementById("dwfrm_bundlesForm_bundleid").value = anchorValue;
				document.getElementById("dwfrm_bundlesForm").submit();
				return false;
			}
		});
	}
	
}

function submitProductSelectionFormNow(){	
	var flag="false";
	
	$("ul.grid li").each(function(index){
		if ($(this).hasClass("selected")){
			flag="true";
			cardSelected = index; 
			var anchorValue = $(this).find("#selected_bundleid1").val();
			var formid = "dwfrm_bundlesForm_bundleproductchosen"+document.getElementById("dwfrm_bundlesForm_bundlecurrentstep").value;
			document.getElementById(formid).value = anchorValue;
			document.getElementById("dwfrm_bundlesForm").submit();
			return false;
		}
	});
	if(flag=="false"){
		$("ul.rotator_info li p.prod_name a").each(function(index){
			if ($(this).hasClass("selected")){
				cardSelected = index; 
				var anchorValue = $(this).find("#selected_bundleid").val();
				var formid = "dwfrm_bundlesForm_bundleproductchosen"+document.getElementById("dwfrm_bundlesForm_bundlecurrentstep").value;
				document.getElementById(formid).value = anchorValue;
				document.getElementById("dwfrm_bundlesForm").submit();
				return false;
			}
		});
	}
}

function submitProductSelectionForm(anchorValue){	
	var formid = "dwfrm_bundlesForm_bundleproductchosen"+document.getElementById("dwfrm_bundlesForm_bundlecurrentstep").value;
	document.getElementById(formid).value = anchorValue;
	document.getElementById("dwfrm_bundlesForm").submit();
}

function submitShadeForm(anchorValue){	
	var formid = "dwfrm_bundlesForm_bundleshadechosen"+document.getElementById("dwfrm_bundlesForm_bundlecurrentstep").value;
	document.getElementById(formid).value = anchorValue;
	document.getElementById("dwfrm_bundlesForm").submit();
}

function addDynamicBundle(anchorvalue,bundleVariance){
	var newArr =new Array();
	newArr = bundleVariance;
	//var bundlevalues = newArr.split(",");
	
	
	//var url = app.util.appendParamToURL(url, "bundleVariant",document.getElementById('hiddenVariance') );
	
	var url = app.util.appendParamToURL(app.minicart.url, "pid",anchorvalue );
	for(var i = 0; i < newArr.length; i++) {
			var url = app.util.appendParamToURL(url, "bundleVariant",newArr[i]);
	}
	
	$.get(url ,function(transport) {
					
		var returnValue = transport;
			try{
				jQuery("#minicart").html(returnValue);
				window.location.href = app.URLs.addDynamicBundle;					
			}catch(e){
				alert(e);
			}
		},"text");
	invokeCoremetrics_AddDynamicBundle(anchorvalue,"BM");
}

function addPreCannedBundle(){
		var pid=document.getElementById('precannedid').value;
		var url = app.util.appendParamToURL(app.minicart.url, "pid",pid );		
		$.get(url ,function(transport) {
			var returnValue = transport;
				try{
					jQuery("#minicart").html(returnValue);
					window.location.href = app.URLs.addDynamicBundle;					
				}catch(e){
					alert(e);
				}
		},"text");
	invokeCoremetrics_AddDynamicBundle(pid,"BM_PRECANNED");
}

function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function changeToProduct(id,isBundle,bundleDivID)
{
	loadImageRed = new Image();
   loadImageRed.src = app.URLs.loadingSmallImg;
	var selected = id;		
	var catid = document.getElementById("cgid").value;
	var deleteid= document.getElementById("deleteuuid").value;
	var temp = app.util.appendParamToURL(app.URLs.bundleSample, "pid",id);
	var url = app.util.appendParamToURL(temp,"cgid",catid);
	url = app.util.appendParamToURL(url,"deletesUUID",deleteid);
	url = app.util.appendParamToURL(url,"bundleVariant",bundleDivID);
	url = app.util.appendParamToURL(url,"isBundle",isBundle);
	url = app.util.appendParamToURL(url,"PAGE_TYPE","pdp");
	$('.content').before('<div class="pop_curtain"><img src='+app.URLs.blankImage+' alt="" width="100%" height="100%" border="0"></div>');
	var cH = Math.max($(window).height(),$(document).height());
	$(".pop_curtain").css({ opacity:0.2, height:cH, width:$(window).width() }).show();
	$(".pop_curtain").bgiframe();
	
	$('.gift_cards_dropdown').hide();
	$.get(url ,function(transport) {						
		var returnValue = transport;
		var pattern=/pricingbox/i;
		var abc = pattern.test(returnValue);
		
		try{
			if($('bundle_shades')) {
				var start_index=returnValue.indexOf("<mainImage>");
				var end_index=returnValue.indexOf('</mainImage>');
				var substring=returnValue.substring(start_index+11,end_index);
				if (substring != null) {						
					document.getElementById('bundle_shades').innerHTML = substring; 
				} else {
					document.getElementById('bundle_shades').innerHTML = '';
				}
			}
			
			if($('open_info')) {
				var start_index=returnValue.indexOf("<infodiv>");
				var end_index=returnValue.indexOf('</infodiv>');
				var substring=returnValue.substring(start_index+9,end_index);
				if (substring != null) {						
					document.getElementById('open_info').innerHTML = substring; 
				} else {
					document.getElementById('open_info').innerHTML = '';
				}
			}
			
			if($('shade-description') && !isBundle) {
				var start_index=returnValue.indexOf('<shade-description>');
				var end_index=returnValue.indexOf('</shade-description>');
				var substring=returnValue.substring(start_index+19,end_index);						
				if (substring != null) {						
					document.getElementById('shade-description').innerHTML = substring; 
				} else {
					document.getElementById('shade-description').innerHTML = '';
				}
			}
			if($('variance_selector')&& !isBundle) {
				var start_index=returnValue.indexOf('<variationSelection>');
				var end_index=returnValue.indexOf('</variationSelection>');
				var substring=returnValue.substring(start_index+20,end_index);
				if (substring != null) {						
					document.getElementById('variance_selector').innerHTML = substring; 
				} else {
					document.getElementById('variance_selector').innerHTML = '';
				}
			} 
			if($('submitForm')&& !isBundle) {
				var start_index=returnValue.indexOf("<submitForm>");
				var end_index=returnValue.indexOf('</submitForm>');
				var substring=returnValue.substring(start_index+12,end_index);	
				if (substring != null) {
					document.getElementById('submitForm').innerHTML = substring; 
				} else {
					document.getElementById('submitForm').innerHTML = '';
				}
			}
			if($(bundleDivID+'variance_selector')&& isBundle) {
				var start_index=returnValue.indexOf("<"+bundleDivID+"variationJSON>");
				var end_index=returnValue.indexOf("</"+bundleDivID +"variationJSON>");
				var substring=returnValue.substring(start_index+35,end_index);	
				if (substring != null) {						
					document.getElementById(bundleDivID).innerHTML = substring; 
				} else {
					document.getElementById(bundleDivID).innerHTML = '';
				}
				updateVariantID(id,(bundleDivID+'_variant'));
			}
			
			//getFlashPlayer();
		}catch(e){
				alert(e);
		}
		
		$(".pop_curtain").remove();
		sifr_replace($("body").attr("class"));
		$(".popup_information").divLayer({layer: ".show_urlindiv", modal: false, vertPosition: "middle", positionedHeight: 558});
		$(".popup_urlindiv").divLayer({layer: ".show_urlindiv", modal: false, vertPosition: "middle", positionedHeight: 558});
		$(".popup_productECdiv").divLayer({layer: ".show_urlindiv", modal: false, vertPosition: "middle", positionedHeight: 558});
		$(".popup_captureEmailTrigger").divLayer({layer: ".popup_captureEmailLayer", modal: false, vertPosition: "middle", positionedHeight: 558});
		$(".popup_content").divLayer({layer: ".show_content", modal: false, vertPosition: "middle", positionedHeight: 558});

		$(function(){
			imagePreview();
			
		});
	},"text");	
	
}

function removeHover(){
	$("#popupDetails").remove();
}

//Function to show product image on mouse hover
this.imagePreview=function(){	
	xOffset = 10;
	yOffset = 30;
	if($('#colorlable').length)
	{
	var colorlabel = document.getElementById('colorlable').value;
	}
	if($('#pricelable').length)
	{
	var pricelabel = document.getElementById('pricelable').value;
	}
	if($('#descriptionlable').length)
	{
	var descriptionlabel = document.getElementById('descriptionlable').value;
	}
	
	$("a.rollOver").hover(function(e){
		var imgSrc = $(this).find('.popUpCnt img').attr('src');			
		var prodTitle = $(this).find('.popUpCnt p.prodTitle').text();
		var prodPrice = $(this).find(".popUpCnt p.prodPrice").html();
		var prodDesc = $(this).find(".popUpCnt p.prodDescription").text();
		if($.browser.msie && $.browser.version=="6.0"){
			$('select').hide();
		}			
		$('body').append("<p id='popupDetails'><span><strong_inline><b>"+colorlabel+":</b>"+prodTitle+"<br/><b>"+descriptionlabel+" :</b> "+prodDesc+"</strong_inline></span><img src='"+ imgSrc +"' alt='Image preview' /><span><b>"+pricelabel+" :</b> "+ prodPrice +"</span></p>");							
		setTimeout(function(){
			$("#popupDetails")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
			updatePopupPosition(e);
			}, 500);
		  },function(){
			$("#popupDetails").remove();
			if($.browser.msie && $.browser.version=="6.0"){
				$('select').show();
				}
		    });	
		};
		
		//Function to update the positin of the pop up window
		function updatePopupPosition(e)
			{
				var windowSize = getWindowSize();
				var popupSize = getPopupSize();
				var settings = jQuery.extend({
				cursorTopOffset: 15,
				cursorLeftOffset: 15
				});
			if (windowSize.width + windowSize.scrollLeft < e.pageX + popupSize.width + settings.cursorLeftOffset){
				$('#popupDetails').css("left", e.pageX - popupSize.width - settings.cursorLeftOffset);				
				$('#popupDetails').find('em').css({left:"230px", backgroundPosition: "0 100%"});
			} else {
				$('#popupDetails').css("left", e.pageX + settings.cursorLeftOffset);				
				$('#popupDetails').find('em').css("left","-13px");
			}
			if (windowSize.height + windowSize.scrollTop < e.pageY + popupSize.height + settings.cursorTopOffset){
				$('#popupDetails').css("top", e.pageY - popupSize.height - settings.cursorTopOffset);				
			} else {
				$('#popupDetails').css("top", e.pageY + settings.cursorTopOffset);				
				}
			}

		//Function that returns the window size 
		function getWindowSize() {
			return {
				scrollLeft: $(window).scrollLeft(),
				scrollTop: $(window).scrollTop(),
				width: $(window).width(),
				height: $(window).height()
				};
			}
						


		//Function that returns the size of the pop up window
		function getPopupSize() {
			return {
				width: $('#popupDetails').width(),
				height: $('#popupDetails').height()
			};
		}

