// begin: argos.product.details
argos.product.details.utils = {
	
	// Set visible list item values
	thresholdHowAbout : 3,
	thresholdAlternatives : 3,
	
	// initialise all page events
	init : function() {
		// reduce namespace
		var productDetails = argos.product.details.utils;
	 
		// add larger image popup event
		$("a.largerimage").click(
			function() {
				Argos.page.spawn(
					this,'newWindow',
					'width=645,height=462,directories=no,location=no,menubar=no,scrollbars=no,toolbar=no,status=no,resizable=no,top=0,left=0'
				);
				return false;
			}
		);
			
		// Set default visible products
		productDetails.showHideProducts('#aswellas', productDetails.thresholdHowAbout);
		productDetails.showHideProducts('#alternatives', productDetails.thresholdAlternatives);
		
		// attach panel toggle effects
		$('#aswellas .showlink').click( 
			function() {
		 		productDetails.showPanelEvent('#aswellas', productDetails.thresholdHowAbout); 
			}
		);

		$('#alternatives .showlink').click( 
			function() {
		 		productDetails.showPanelEvent('#alternatives', productDetails.thresholdAlternatives); 
			}
		);
		
		// add print button to page
		productDetails.makePrintPage();
		
		//reviews set up
		productDetails.reviewsUtils();
		
		productDetails.richerContentUtils();
		
	}, //end init()
	
	// Output print button in javascript
	makePrintPage : function() {
		// get defensive
		if(!window.print) return; 
		$('<li id="printpage"><button type="button" title="Click here to print this page"><span>Print page</span></button></li>').insertAfter("#emailfriend");
		// Apply Print event
		$("#printpage button").mousedown( 
			function() {  
				window.print();
			}
		); 
	},
	
	// Show All Functionality
	// toggle accordian and showall message
	showAllLine : function(id, totalLI, threshold) {
		var originalThreshold = threshold;
		var showalltext = "Show all";
		var containerRef = $(id)[0];
		var msg = '';
		var expanded = false;
		
		if (!containerRef) return;
		// set correct threshold if products are lower than that value
		if (threshold > totalLI){ 
				threshold = totalLI;
				showalltext = "";
			} 		
		var idmsg = id + " .showallline";
		// show expanded state
		if(expanded) {
			msg = '<span class="showalllink hidelink">Hide </span><span class="showing">(showing ' + totalLI + ' of ' + totalLI + ')</span>';
			expanded = false;
		} else {
		// show contracted state
			msg = '<span class="showalllink showlink">' + showalltext + '</span><span class="showing">(showing ' + threshold + ' of ' + totalLI + ')</span>';
			expanded = true;
		}
	
		if(originalThreshold >= totalLI) {
			msg = '&nbsp;'; // soz - temporary IE height filler
		}
			
		$(idmsg).html(msg);
	}, // end showAllLine()
	
	// hide all but the visible threshold limit
	showHideProducts : function (id, threshold) {
		var productRef = id + ' .product';	 // get reference to the products
		var totalLI = $(productRef).length; // find length of list
		var modThreshold = threshold - 1; // modThreshold is threshold adjusted for porduct count
		var strProductQuery = productRef + ':gt(' + modThreshold + ')';	
	
		$(strProductQuery).hide();	// hide all but the visible threshold numbers
		argos.product.details.utils.showAllLine(id, totalLI, threshold);	// showAllLine ouputs the correct values
		
		// hide last product line
		$(productRef + ":gt(" + (threshold-2) + ")").css(
			{ border : 'none'}
		);
	},
	
	showPanelEvent : function(id, threshold) {
		var containerRef = $(id)[0];
		if(!containerRef) return;
		var expanded = false;
		var setTarget = id + ' > ul > li:gt(0)';
		var panelThreshold = 0;
		
		// show message
		var idmsg = id + " .showallline";
		var msg ="";			
		var productRef = id + ' .product';	 // get reference to the products
		var totalLI = $(productRef).length; // find length of list
		var modThreshold = threshold - 1; // modThreshold is threshold adjusted for porduct count
		var showalltext = "Show all";
	
		// set correct threshold if products are lower than that value
		if (threshold > totalLI){ 
			threshold = totalLI;
			showalltext = ""; //
		} 
	
		// check for expanded
		if ( $(id)[0].className.indexOf('expanded') != -1 ) {
			
			setTarget = id + ' > ul > li:gt('+ (threshold-1) +')';
			$(setTarget).slideUp("slow", 
				function() {
					$(id).find('.showalllink').html('Show all');
					$(id).find('.showing').html('(showing ' + 
										threshold + ' of ' + totalLI +
										 ')');
				}
			);
		
			$(id).removeClass('expanded');
			$(id).find(".showallline").removeClass('expanded');
			// hide last threshold product line
			$(productRef + ":gt(" + (threshold-2) + ")").css(
				{ border : 'none'}
			);
		} // end of (indexOf('expanded'))
		
		else {
			// if unexpanded
			// set expanded className
			// show last threshold product line
			
			setTarget = id + ' > ul > li:gt(0)';
			$(productRef).css(
				{ borderBottom : '1px solid #9c9c9c'}
			);
			$(setTarget).slideDown("slow", 
				function() {
				// show expanded state
				$(id).find('.showalllink').html('Hide');
				$(id).find('.showing').html('(showing ' + 
									totalLI + ' of ' + totalLI +
									 ')');
				}
			);
			
			$(id).addClass('expanded');
			$(id).find(".showallline").addClass('expanded');
		}// end className.indexOf("expanded")
		
		// render message
		
	}, // end showPanelEvent()
	
	reviewsUtils : function() {	
		// hide iframe for js enabled users and change iframe src
		if ($("BVFrame")) {
			var frame = $("#BVFrame");
			frame.addClass("jsHide");
			// replace format value in src path to ensure correct visual formatting within iframe
			
			/* removed for now, due to load state timeout issue, DG
			var frameSrcValue = frame.attr("src");
			frame.attr("src", frameSrcValue.replace(/noscript/i, "embedded"));		
			*/	
		};
	},	

	richerContentUtils : function() {
		if ($(".multimediaactions li")) {		
			$(".multimediaactions li").each(function (){this.style.display="inline";});			
		}
		if ($(".proddetails span.newwindowtext")) {
			$(".proddetails span.newwindowtext").each(function (){this.style.display="block";});			
		}		
	}

} // end argos.product.details


$(document).ready(
	function() {
		// initialise page
		argos.product.details.utils.init();
	
	} // end of doc.ready	
);

 