function doFlashTab(url, width, height) {
	var fcid = "flashtab_contents";
	$("#videoTab span.content").attr("id", fcid);
	var so = new SWFObject(url, fcid + "_movie", width, height, "8");	
	so.addParam("wmode", "opaque");		
	so.write(fcid);	
	$("#videoTab").show();
}

var _gpid;

function doPhotoTab(){
var metadata = $("#photoTab span.metadata").html();			
	var bgcolor, pid, url, itemdict;	
	var props = metadata.split(",");
	for(var i = 0; i < props.length; i++) {
		itemdict = props[i].split(":");
		switch(itemdict[0]) {
			case "id": pid = itemdict[1]; break;
			case "color": bgcolor = itemdict[1]; break;
		}
	}
	
	_gpid = pid;
	fetchAlts(pid);
}

function destroyFlashTab(id) { $("#" + id + " span.contents").html(''); }

function showMediaTab(url, width, height, showFirst, mediaTabText){

$(document).ready(function() {	
	$("ul.imageTabsNav").show();
	$("#photoTabLink").click(function() {
		$("#videoTabLink").removeClass("active");						
		$("#photoTabLink").addClass("active");
		destroyFlashTab('videoTab');
		$("#videoTab").hide();
		$("#photoTab").show();		
		doPhotoTab();		
		return false;
	});
		
	$("#videoTabLink").click(function() {
		$("#photoTabLink").removeClass("active");
		$("#videoTabLink").addClass("active");
		destroyFlashTab('photoTab');
		$("#photoTab").hide();
		$("#videoTab").show();		
		doFlashTab(url, width, height);		
		return false;
	});
	$("#videoTabLink").html(mediaTabText);
	
	if (showFirst) $("#videoTabLink").click();
	else $("#photoTabLink").click();
	});
}	//end showMedia function

var currentTab = 0; 

//configure tab regions on page
$(document).ready(function() {			
	
	doPhotoTab();	

	// tabbed info box	
	function openTab(clickedTab) {
		var trackString = "productdetail:tabs:" + clickedTab.html(); //omniture tracking
		s_omni.tl(true, "o", trackString);	//omniture tracking
		var thisTab = $(".tabs .tabsNav a").index(clickedTab);	
		$(".tabs .tabsNav li").removeClass("active");
		$(".tabs .tabsNav li:eq("+thisTab+")").addClass("active");
		$(".tabs .tabbed-content").hide();
		$(".tabs .tabbed-content:eq("+thisTab+")").show();
		currentTab = thisTab;
	}

	$(".tabs .tabsNav li a").click(function() {
		openTab($(this)); return false;
	});
	
	$(".tabs .tabsNav li a:eq("+currentTab+")").click();
	
	//--------------------------------------------------------------------------------
	
		    /* Remove personalization tools from multi-item pages of D23 products (duffel bags/etc. use CYO tech for D23 logo)    */    
        $(".listBoxDesc").each(function(index){
            var myDPText = $(this).find(".dealPricing").text();
            if (($.trim(myDPText) == "D23 Membership Required") || $(this).find("h2 a:contains('D23')")) {
                var myPzButton = $(this).find("p a img.pzButton");
                if (myPzButton) {
                    myPzButton.parent().parent().css("display", "none");
                }
            }
            else {

            }
        });

/* Add D23 details to item, based on cookies  */
        if ((typeof isD23Gated != "undefined") && (isD23Gated == true) && $('span.d23-contents')) {
		

		
			//setCookie('BLUE','yes');
			//setCookie('d23Member','yes');
            if (getCookie('BLUE')) {
                //cookie DOES EXIST AND NOT EMPTY SO LOGGED IN.
                //so toggle the 2 divs.. turn nologin div on
                /*
                 * <span>This product is available exclusively to D23 Members.
                 * If you are a member, please <a href="/disney/store/DSILogonForm_10002_10054_-1_10051">log in.</a>
                 * If you'd like to become a member,
                 * <a href="/buy-a-d23-membership/c/66520/">click here.</a></span>
                 */
                if (getCookie('BLUE') != '""') {
                    if (getCookie('d23Member')) {
					
                        $('span.d23-contents').css('display', 'none');
                    }
                    else {
			
						$('span.d23-contents').css({'padding' : '8px' , 'border' : '1px solid #d7d4cb','display' : 'block' , 'background-color' : '#e5dfcf', 'color' : '#591b0e'}).html('<strong>This product is available exclusively to D23 members.</strong><ul style="list-style-type:disc; margin-left: 15px;"><li>Not a member? <a href="/buy-a-d23-membership/c/66520/"><img style="vertical-align:middle; border:0;" src="//aimg.disneystore.com/content/ds/themes/default10/d23join.gif"></a></li></ul>');                     
					}
                }
                else {
                    //cookie exists but is EMPTY - logged out after logging in Asis D23 Member
                    if (getCookie('d23Member')) {
                        //$('span.d23-contents').css('display', 'block').html('<span>This product is available exclusively to D23 Members. <br /><br />If you are a member, please <a href="/disney/store/DSILogonForm_10002_10054_-1_10051">log in.</a>');
						$('span.d23-contents').css({'padding' : '8px' , 'border' : '1px solid #d7d4cb','display' : 'block' , 'background-color' : '#e5dfcf', 'color' : '#591b0e'}).html('<strong>This product is available exclusively to D23 members.</strong><ul style="list-style-type:disc; margin-left: 15px;"><li>If you are a member, please log in. <a href="#" onClick="showLoginModal();"><img style="vertical-align:middle; border:0;" src="//aimg.disneystore.com/content/ds/themes/default10/d23login.gif"></a></li></ul>');
					
					}
                    else {
                        //d23 member do something to tailor the text to tell them to login
                        //$('span.d23-contents').css('display', 'block');
					
						$('span.d23-contents').css({'padding' : '8px' , 'border' : '1px solid #d7d4cb','display' : 'block' , 'background-color' : '#e5dfcf', 'color' : '#591b0e'}).html('<strong>This product is available exclusively to D23 members.</strong><ul style="list-style-type:disc; margin-left: 15px;"><li>If you are a member, please log in. <a href="#" onClick="showLoginModal();"><img style="vertical-align:middle; border:0;" src="//aimg.disneystore.com/content/ds/themes/default10/d23login.gif"></a></li><li>Not a member? <a href="/buy-a-d23-membership/c/66520/"><img style="vertical-align:middle; border:0;" src="//aimg.disneystore.com/content/ds/themes/default10/d23join.gif"></a></li></ul>');
                    }
                }

            }
            else {
                
                //cookie BLUE doesn't exist - need to do the login form
			$('span.d23-contents').css({'padding' : '8px' , 'border' : '1px solid #d7d4cb','display' : 'block' , 'background-color' : '#e5dfcf', 'color' : '#591b0e'}).html('<strong>This product is available exclusively to D23 members.</strong><ul style="list-style-type:disc; margin-left: 15px;"><li>If you are a member, please log in. <a href="#" onClick="showLoginModal();"><img style="vertical-align:middle; border:0;" src="//aimg.disneystore.com/content/ds/themes/default10/d23login.gif"></a></li><li>Not a member? <a href="/buy-a-d23-membership/c/66520/"><img style="vertical-align:middle; border:0;" src="//aimg.disneystore.com/content/ds/themes/default10/d23join.gif"></a></li></ul>');
			}
        }
		
	    /* Add Disney Collector details to item  */	
		if ((typeof isCollectorGated != "undefined") && (isCollectorGated == true) && $('span.d23-collector')) {
			$('span.d23-collector').css({'display' : 'block'}).html("<span>This product is available exclusively to Walt Disney Collector's Society Members.<br><br>If you'd like to become a member, <a href='/collectors-society-wdcs-2009-membership-kit-with-dopey-figurine-pin-lithograph/p/1241807/13838/'>click here.</a></span><p><strong>Note to current members of the Walt Disney Collectors Society: Please provide your WDCS Member ID and Member Last Name in the fields below in order to purchase Members-Only Pieces.</strong></p> <p>The Walt Disney Collectors Society celebrates Disney's magical legacy through the sculptures of the Walt Disney Classics Collection. Created by Disney artists, these award-winning sculptures bring to three-dimensional life actual film moments from Disney's most unforgettable animated classics.</p> <p>Each porcelain sculpture is handcrafted to convey the magic of our favorite characters and treasured moments. Join today and receive the 2009 Membership Gift Sculpture -- Dopey: ''Gleeful Grin'' -- free with paid membership. Sculpted by Bruce Lau. 5'' H. Porcelain. In addition, you can purchase the Snow White Apple Ornament: ''Sweet Surprise'' (offered separately) to display with Dopey. Imported. Certificate of Authenticity.</p> <p><strong>Exclusive Benefits for 2009 Members of the Walt Disney Collectors Society include:</strong></p> <ul> <li>Free Dopey: ''Gleeful Grin'' Sculpture</li> <li>Opportunities to purchase other exclusive Members-Only Pieces</li> <li>A sketch lithograph of the concept art for the Dopey Membership Gift Sculpture</li> <li>A full-color lithograph from Walt Disney's <em>Snow White and the Seven Dwarfs</em></li> <li>Personalized membership card</li> <li>Exclusive membership pin featuring Dopey</li> <li>Advance notice of new releases and special events</li> <li>Plus, even more members-only magic all year long!</li> </ul></p>");
          
		}



//---------------------------------------------------------------------------------

});


function showBVReviewsTab() {
	//alias function for bazaarvoice to call
	var res = $.scrollTo('div.tabs');

	var res = $('.tabsNav a.reviews').click();
}

//map page links to tabs as appropriate
$(document).ready(function() {	
	$('a.readReviews').click(function() {
		$('.tabsNav a.reviews').click();
	});

	$('a.readSize').click(function() {
		$('.tabsNav a.size').click();
	});

	$('p.shippingMessage a').click(function() {
		$('.tabsNav a.shipping').click();
	});
	
});

var altMaxCheck = 3;
var altPreloader = new Array();
function fetchAlts(s7id) {
	for(var i = 0; i < altMaxCheck; i++) {
		altPreloader[i] = new Image();
		altPreloader[i].alt = '0';
		altPreloader[i].onload = function() { this.alt = '1'; }
		altPreloader[i].src = 'http://as7.disneystore.com/is/image/DisneyShopping/' + s7id + '-' + (i + 1) + '?$tiny$';
	}
	var gc = setTimeout("fetchAltsCallBack('" + s7id + "')", 1500);	
}

function fetchAltsCallBack(pid) {
	var cpidstring = 'DisneyShopping/' + pid;
	for(var j = 0; j < altMaxCheck; j++) { 
		if(altPreloader[j].alt == '1') {
			cpidstring = cpidstring + ',DisneyShopping/' + pid + '-' + (j + 1); 
		}
	}
	
	//TODO: move following into IPS renderset
	url = "http://aimg.disneystore.com/content/ds/themes/default11/flash/genericzoom.swf";
			url += '?serverUrl=http://as7.disneystore.com/is/image';
			url += '&image=' + cpidstring;
			url += '&config=DisneyShopping/RenderSetConfigDefaults';
			url += '&backgroundColor=0xffffff';
	        	url += '&logo2=false';
			url += '&ztgBorderColor=0xd1d1d1';
			url += '&ztgBorderThickness=1';
			url += '&ztgLayout=none';
			url += '&ztgCellSpacing=0,7';
			url += '&skin=http://aimg.disneystore.com/content/ds/themes/default11/flash/zoomSkinTemplateFG.swf,http://aimg.disneystore.com/content/ds/themes/default11/flash/zoomSkinTemplateBG.swf';
			url += '&swBorderColor=0xd1d1d1';
			url += '&swBorderThickness=1';
			url += '&swHighlightThickness=1';
			url += '&swHighlightColor=0x5A86AC';
			url += '&swDoReset=true';
			url += '&autoResize = false,false';
		url += '&viewSize = 0,0';
	
	var productImgAlt = "DisneyStore.com Item Image";
	if ((typeof productName!= "undefined")&&(productName)) productImgAlt = productName;
	
	//alert(staticOnly);
	if ((typeof staticOnly!= "undefined")&&(staticOnly)){
		if (deconcept.SWFObjectUtil.getPlayerVersion().major >= 9) {
			$("#photoTab span.content").html('<style type="text/css">#photoTab{min-height: 332px;}</style><img alt="' + productImgAlt + '" width="300" height="300" src="http://as7.disneystore.com/is/image/DisneyShopping/' + pid + '?$full$"><br/><div style="background-color: #d0dae3; text-align:center; padding: 5px;"><a href="#" onClick="doMoreViewsPopup();"><img src="//aimg.disneystore.com/content/ds/themes/default11/moreViews.gif"></a></div>');
			}
		else {
				$("#photoTab span.content").html('<style type="text/css">#photoTab{min-height: 300px;}</style><img alt="' + productImgAlt + '" width="300" height="300" src="http://as7.disneystore.com/is/image/DisneyShopping/' + pid + '?$full$"');
			}
		}
	else{
			if (deconcept.SWFObjectUtil.getPlayerVersion().major >= 9) {
				var fcid = "phototab_contents_" + pid;
				$("#photoTab span.content").attr("id", fcid);	
				var so = new SWFObject(url, fcid + "_movie", 294, 420, "8", "#FFFFFF");	
				so.addParam("allowScriptAccess", "always");		
				so.addParam("wmode", "opaque");	
				so.write(fcid);
			} else {
				$("#photoTab span.content").html('<style type="text/css">#photoTab{min-height: 300px;}</style><img alt="' + productImgAlt + '" width="300" height="300" src="http://as7.disneystore.com/is/image/DisneyShopping/' + pid + '?$full$"');
			}
		}
}

function doMoreViewsPopup() {
	if(_gpid) {
		var purl = "http://aimg.disneystore.com/content/ds/themes/default11/flash/s7.html?pid=" + _gpid;
		var res = popupDimensions(purl, "599", "716");
	}
}
