//
//-------------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (c) Copyright IBM Corp. 2006
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//-------------------------------------------------------------------
//

//
// ***
// * This javascript library contains a number of functions used for the display
// * of media (i.e. large image, print view, zoom, video) on the product detail page
// ***
//

// function to display the large image of the product
function displayLargeImage(filename)
{
	large_image = window.open('','movie','width=370, height=500');
	large_image.document.writeln("<html><title></title><body><div align='center'>");
	large_image.document.writeln("<img src='"+filename+"'/>");
	large_image.document.writeln("<br/><br/><a href='#' onClick='window.close()'><strong>Close</strong></a></div></body></html>");
	large_image.document.close();
}


// function to display the print view of the product
function openPrintWindow(url) {
	print_popup = window.open(url,'','width=640,height=750,resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}


// function to display the zoom image of the product
function openZoomWindow(url) {
	print_popup = window.open(url,'','width=495,height=520,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}
// function to display the text a friend page
function openTextAFriendWindow(url){
    print_popup = window.open(url,'','width=515,height=480,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
    }
    
// function to display the email a friend page
function openEmailAFriendWindow(url){
    print_popup = window.open(url,'','width=515,height=670,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
    }   

// function to display the video of the product
function openVideoWindow(url) {
	print_popup = window.open(url,'','width=870,height=690,resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no');
}

// function to switch the product detail large image for a large image alternative
// backupImage is a fall back image if the product does not have a large
function displayLargeAltImage(largeAltImage, backupImage) {
	if (largeAltImage.length < 26) {
		document.images.main_image.src = backupImage
	} else {
		document.images.main_image.src = largeAltImage; 
	}
}

// function to switch between tabs on the product detal page
// there was a clever function for doing this by switching the src attribute
// on the tab images - IE7 didn't like it.
function showTab(elementId) {
	document.getElementById('product_page_description').style.display = "none";
	document.getElementById('product_page_reviews').style.display = "none";
	document.getElementById('product_page_specs').style.display = "none";
	document.getElementById('product_page_delivery').style.display = "none";
	document.getElementById('product_page_service_comments').style.display = "none";
	document.getElementById('product_page_faq').style.display = "none";
	document.getElementById(elementId).style.display = "inline";	
	if (elementId == 'product_page_reviews') {
		document.getElementById('pdp_reviews_tab').style.display = "none";
		document.getElementById('pdp_reviews_tab_current').style.display = "inline";
		document.getElementById('pdp_description_tab').style.display = "inline";
		document.getElementById('pdp_description_tab_current').style.display = "none";
		document.getElementById('pdp_specs_tab').style.display = "inline";
		document.getElementById('pdp_specs_tab_current').style.display = "none";	
		document.getElementById('pdp_delivery_tab').style.display = "inline";
		document.getElementById('pdp_delivery_tab_current').style.display = "none";
		document.getElementById('pdp_service_comments_tab').style.display = "inline";
		document.getElementById('pdp_service_comments_tab_current').style.display = "none";	
		document.getElementById('pdp_faq_tab').style.display = "inline";
		document.getElementById('pdp_faq_tab_current').style.display = "none";		
	} else if (elementId == 'product_page_description') {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_description_tab').style.display = "none";
		document.getElementById('pdp_description_tab_current').style.display = "inline";
		document.getElementById('pdp_specs_tab').style.display = "inline";
		document.getElementById('pdp_specs_tab_current').style.display = "none";
		document.getElementById('pdp_delivery_tab').style.display = "inline";
		document.getElementById('pdp_delivery_tab_current').style.display = "none";
		document.getElementById('pdp_service_comments_tab').style.display = "inline";
		document.getElementById('pdp_service_comments_tab_current').style.display = "none";			
		document.getElementById('pdp_faq_tab').style.display = "inline";
		document.getElementById('pdp_faq_tab_current').style.display = "none";				
	}else if (elementId == 'product_page_specs') {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_description_tab').style.display = "inline";
		document.getElementById('pdp_description_tab_current').style.display = "none";
		document.getElementById('pdp_specs_tab').style.display = "none";
		document.getElementById('pdp_specs_tab_current').style.display = "inline";	
		document.getElementById('pdp_delivery_tab').style.display = "inline";
		document.getElementById('pdp_delivery_tab_current').style.display = "none";
		document.getElementById('pdp_service_comments_tab').style.display = "inline";
		document.getElementById('pdp_service_comments_tab_current').style.display = "none";			
		document.getElementById('pdp_faq_tab').style.display = "inline";
		document.getElementById('pdp_faq_tab_current').style.display = "none";				
	} else if (elementId == 'product_page_delivery') {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_description_tab').style.display = "inline";
		document.getElementById('pdp_description_tab_current').style.display = "none";
		document.getElementById('pdp_specs_tab').style.display = "inline";
		document.getElementById('pdp_specs_tab_current').style.display = "none";
		document.getElementById('pdp_delivery_tab').style.display = "none";
		document.getElementById('pdp_delivery_tab_current').style.display = "inline";
		document.getElementById('pdp_service_comments_tab').style.display = "inline";
		document.getElementById('pdp_service_comments_tab_current').style.display = "none";	
		document.getElementById('pdp_faq_tab').style.display = "inline";
		document.getElementById('pdp_faq_tab_current').style.display = "none";				
	} else if (elementId == 'product_page_service_comments') {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_description_tab').style.display = "inline";
		document.getElementById('pdp_description_tab_current').style.display = "none";
		document.getElementById('pdp_specs_tab').style.display = "inline";
		document.getElementById('pdp_specs_tab_current').style.display = "none";
		document.getElementById('pdp_delivery_tab').style.display = "inline";
		document.getElementById('pdp_delivery_tab_current').style.display = "none";
		document.getElementById('pdp_service_comments_tab').style.display = "none";
		document.getElementById('pdp_service_comments_tab_current').style.display = "inline";	
		document.getElementById('pdp_faq_tab').style.display = "inline";
		document.getElementById('pdp_faq_tab_current').style.display = "none";				
	} else {
		document.getElementById('pdp_reviews_tab').style.display = "inline";
		document.getElementById('pdp_reviews_tab_current').style.display = "none";
		document.getElementById('pdp_description_tab').style.display = "inline";
		document.getElementById('pdp_description_tab_current').style.display = "none";
		document.getElementById('pdp_specs_tab').style.display = "inline";
		document.getElementById('pdp_specs_tab_current').style.display = "none";
		document.getElementById('pdp_delivery_tab').style.display = "inline";
		document.getElementById('pdp_delivery_tab_current').style.display = "none";
		document.getElementById('pdp_service_comments_tab').style.display = "inline";
		document.getElementById('pdp_service_comments_tab_current').style.display = "none";	
		document.getElementById('pdp_faq_tab').style.display = "none";
		document.getElementById('pdp_faq_tab_current').style.display = "inline";	
	}
}


function showMediaTab(elementId) {
	document.getElementById('large_image_display').style.display = "none";
	document.getElementById('zoom_display').style.display = "none";
	document.getElementById('video_display').style.display = "none";
	document.getElementById(elementId).style.display = "inline";	
	if (elementId == 'large_image_display') {
		document.getElementById('pdp_large_image_tab').style.display = "none";
		document.getElementById('pdp_large_image_tab_current').style.display = "inline";
		document.getElementById('pdp_zoom_tab').style.display = "inline";
		document.getElementById('pdp_zoom_tab_current').style.display = "none";
		document.getElementById('pdp_video_tab').style.display = "inline";
		document.getElementById('pdp_video_tab_current').style.display = "none";		
	} else if (elementId == 'zoom_display') {
		document.getElementById('pdp_large_image_tab').style.display = "inline";
		document.getElementById('pdp_large_image_tab_current').style.display = "none";
		document.getElementById('pdp_zoom_tab').style.display = "none";
		document.getElementById('pdp_zoom_tab_current').style.display = "inline";
		document.getElementById('pdp_video_tab').style.display = "inline";
		document.getElementById('pdp_video_tab_current').style.display = "none";
	} else if (elementId == 'video_display') {
		document.getElementById('pdp_large_image_tab').style.display = "inline";
		document.getElementById('pdp_large_image_tab_current').style.display = "none";
		document.getElementById('pdp_zoom_tab').style.display = "inline";
		document.getElementById('pdp_zoom_tab_current').style.display = "none";
		document.getElementById('pdp_video_tab').style.display = "none";
		document.getElementById('pdp_video_tab_current').style.display = "inline";	
	}
}


function loadVideo(videoSource, type) {
	blankMediaDisplay('large_image_display');
	blankMediaDisplay('zoom_display');
	if (type == 'youtube') {
		var videoString = '<div style="width:100%;"><object width="374" height="306"><param name="movie" value="http://www.youtube.com/'+videoSource+'&hl=en&fs=1&ap=%2526fmt%3D22&autoplay=1" type="application/x-shockwave-flash" width="374" height="306" allowfullscreen="true" wmode="transparent" /><embed src="http://www.youtube.com/'+videoSource+'&hl=en&fs=1&ap=&fmt=22&autoplay=1" type="application/x-shockwave-flash" width="374" height="306" wmode="transparent" allowfullscreen="true" /></object></div><div style="width:99%;"><a href="http://www.youtube.com/user/Kiddicare">Kiddcare on youtube</a><br/><a href="wcsstore/ConsumerDirect/images/video/install_flash_player.exe">No video? Download Flash player here</a><br/><br/><span style="font-size:80%;"><u><strong>Important Information</strong></u><br/>This video is a guide to the product, please read the product item page for full information to establish what is included within the price of your purchase.<br/></span></div>';	
	} else {
		var videoString = '<div style="width:100%;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="374" height="320" id="video" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /><param name="movie" value="'+videoSource+'.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><parameter name="wmode" value="transparent" /><embed src="'+videoSource+'.swf" quality="high" bgcolor="#ffffff" width="374" height="320" wmode="transparent" name="Kiddicare video" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="//www.macromedia.com/go/getflashplayer" allowFullScreen="true" /></object></div><div style="width:99%;"><a href="wcsstore/ConsumerDirect/images/video/install_flash_player.exe">No video? Download Flash player here</a><br/><br/></div>';
	}
	document.getElementById('video_display').innerHTML = videoString;
	document.getElementById('video_display').style.display = 'block';
}

function showLargeImage(imageSource, imageAlt) {
	blankMediaDisplay('video_display');
	blankMediaDisplay('zoom_display');
	document.getElementById('large_image_display').innerHTML = '<img src="'+imageSource+'" alt="'+imageAlt+'" name="main_image" />';
	document.getElementById('large_image_display').style.display = 'block';	
}

function loadZoom(zoomSource) {
	blankMediaDisplay('large_image_display');
	blankMediaDisplay('video_display');
	blankMediaDisplay('zoom_display');
	document.getElementById('zoom_display').innerHTML = '<object id="fsiviewer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0" width="350px" height="400px" wmode="transparent"><param name="movie" value="http://62.128.130.204:8180/erez3/fsi3/fsi.swf?showcase_server=http://62.128.130.204:8180/erez3&showcase_dir=' + zoomSource + '/&cfg=showcase_presets/plain&showcase_Align=bottom&plugins=resize,clockprogress&Skin=plain"><param name="menu" value="FALSE" /><param name="wmode" value="transparent" /><embed src="http://62.128.130.204:8180/erez3/fsi3/fsi.swf?showcase_server=http://62.128.130.204:8180/erez3&showcase_dir=' + zoomSource + '/&cfg=showcase_presets/plain&showcase_Align=bottom&plugins=resize,clockprogress&Skin=plain" width="350px" height="400px" name="fsiviewer" menu="false" wmode="transparent" pluginspage="//www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"/></object>';
	document.getElementById('zoom_display').style.display = 'block'
}

function loadZoomImages() {
	blankMediaDisplay('large_image_display');
	blankMediaDisplay('video_display');
	document.getElementById('zoom_display').style.display = 'block';
}

function blankMediaDisplay(mediaElement) {
	if (mediaElement == 'large_image_display' || mediaElement == 'zoom_images_display') {
		document.getElementById(mediaElement).style.display = 'none';	
	} else {
		document.getElementById(mediaElement).innerHTML = '';
		document.getElementById(mediaElement).style.display = 'none';
	}
}



