/***********************************************/
/* Start :  Gallery shortcut links, auto spacing function         */
$jq('.gallery_selector').ready(function() {						  
	var links;
	var total;
	var i;
	var margin;
	var totalMargins;
	var totalDividersWidth;
	var totalImageWidths;
	var dividerWidth 	= 2;
	var containerWidth 	= 302;
	links	= $jq('.gallery_selector').find ('li a');
	total	= links.length;

	if (total != 0){
		totalDividersWidth 	= ( total -1 ) * dividerWidth;
		totalImageWidths	= total * 65;
		totalMargins		= containerWidth	- totalImageWidths - totalDividersWidth -7 ;
		margin				= Math.floor((totalMargins) / (total * 2)) -1 ;
		links.css('paddingLeft',margin);
		links.css('paddingRight',margin);
	}

});
/* End :  Gallery shortcut links, auto spacing function         */
/***********************************************/

/***********************************************/
/* Start :  Work around to use rounded corners for overview section         */

$jq('.product_detail_tab_overview').livequery(function() { 
	if ($jq(this).find ('.rc-inner').length == 0)												 
	drawRoundedCornersForAjaxContent (this); 
});

$jq('#bonusRounded').livequery(function() { 
	if ($jq(this).find ('.rc-inner').length == 0)												 
	drawRoundedCornersForAjaxContent (this); 
});



/* End :  Work around to use rounded corners for overview section         */
/***********************************************/

/***********************************************/
/* Start :  Tabbed content height resize hack         */



//-- used in product details page to control the height of the content area
function calculateTabContentHeight (){
	var tabContentDomObj;
	var browsingHistoryDomObj;
	var height;
	
	target	= $jq('.pro_details_tabs .content')[0];
	browsingHistoryDomObj = $jq('#browsehist')[0];
	
	if (browsingHistoryDomObj == null)
		browsingHistoryDomObj = $jq('#suppshortcut')[0];
		
	if (browsingHistoryDomObj != null && target != null){
		if ($jq('.pro_details_tabs .content').length != 0){
			
			if ($jq(browsingHistoryDomObj).css ('display') == "none"){
				$jq(target).css('height', '');
			}
			/*else{
				$jq(target).css('height', '');
				height = findPosY (browsingHistoryDomObj)	- findPosY (target) -53;

				if ($jq(target).height() > height)
					height	= $jq(target).height();
	
				$jq(target).css('height', height);
			}*/
		}
	}
}

function initProductDetailsPageMethods (){
	//-- firefox workaround for first load

	pollForContentHeightChange ();
	 //-- do check when ajax content has completed loading
	$jq('.pro_details_tabs').ajaxStop(function(){window.setTimeout ('calculateTabContentHeight ()', 500);});
	//-- add functions to font resize controls to do checks
	$jq('.adjusticonpanel').find('a').each(function(){addFontResizeCheckToButtons (this)});
	//--add resize checks to print buttons
	$jq('.printtool').find('a').each(function(){addFontResizeCheckToButtons (this)});
	//--add resize checks to back to webview button
	$jq('.TopPrintButton .BackButton').find('a').each(function(){addFontResizeCheckToButtons (this)});


}

function pollForContentHeightChange (){
	var presentHeight  = $jq('.pro_details_tabs .content').height();
	var newHeight;
	calculateTabContentHeight ()
	newHeight = $jq('.pro_details_tabs .content').height();
	
	if (presentHeight != newHeight){
		window.setTimeout ('pollForContentHeightChange ()',500);
	}
}

function addFontResizeCheckToButtons (target){
	var defaultfunctions;
	var updatedfunctions;

	defaultfunctions	= $jq(target).attr("onclick");
	
	if ($jq.browser.msie){
		defaultfunctions	= getFunctionContents (defaultfunctions);
		updatedfunctions	= "window.setTimeout ('calculateTabContentHeight ()', 100);" + defaultfunctions ;
		updatedfunctions	= new Function (updatedfunctions);
		target.onclick		= updatedfunctions;
	}
	else{
		updatedfunctions	= "window.setTimeout ('calculateTabContentHeight ()', 100);" + defaultfunctions; 
		 $jq(target).attr("onclick", updatedfunctions);
	}

}



addLoadEvent (initProductDetailsPageMethods);
/* End :  Tabbed content height resize hack         */
/***********************************************/

/***********************************************/
/* Start :  product details minimise menus script         */

function expand_pro_detail_tab_spec(content_div_id, title_div_id){
	var content_div = document.getElementById(content_div_id);	
	var title_div = document.getElementById(title_div_id);	

	if( content_div != null ){
		content_div.className = (content_div.className == 'spec_sheet' ? 'spec_sheet_hidden':'spec_sheet');
	}
	if( title_div != null ){
		title_div.className = (title_div.className == 'title_icon' ? 'title_icon_expand':'title_icon');
	}
}


//Start : TabMenu Scroll

$jq(document).ready(function() {						  
var widthh=0;
$jq(".TabMenu li").each(function() {
	widthh+=$jq(this).width();
});

if (widthh>655)
{
	$jq('.TabMenu ul').css('width',widthh);
	$jq('.TabMenu').css('overflow-x',"scroll");
}
});

// End : TabMenu Scroll 

// Start TabMenu Height Fix 

jQuery(document).ready(function($){
	
	var maxHeight = 0;
	$jq("#ajaxTabs ul li").each(function() {
	if($jq(this).height() > maxHeight){maxHeight = $jq(this).height();}			
	});
	$jq('#ajaxTabs ul li').css('height',maxHeight);
	$jq('#ajaxTabs ul li a').css('height',maxHeight-16);
	$jq('#ajaxTabs ul li a span').css('height',maxHeight-16);

});
// End TabMenu Height Fix 
