﻿if(typeof($) == 'function' )
{

	$('#modalWindow').ready(function(){
		if ($(window).height() < document.getElementById('modalWindow').clientHeight) {
			document.getElementById('overlayContentDiv').style.height = ($(window).height() - 50) + "px";
			document.getElementById('overlayContentDiv').style.overflow = "auto";
		}

		newPosition = Math.round(($(window).height() - document.getElementById('modalWindow').clientHeight) / 2);

		if ($.browser.msie && (parseInt($.browser.version) < 7)) {
			// fix for ie 6?
		} else {
			document.getElementById('modalWindow').style.top = newPosition + "px";
		}
	});

//	$('#modalWindowSmall').ready(function(){
//		if ($(window).height() < document.getElementById('modalWindowSmall').clientHeight) {
//			document.getElementById('overlayContentDiv').style.height = ($(window).height() - 50) + "px";
//			document.getElementById('overlayContentDiv').style.overflow = "auto";
//		}

//		newPosition1 = Math.round(($(window).height() - document.getElementById('modalWindowSmall').clientHeight) / 2);

//		if ($.browser.msie && (parseInt($.browser.version) < 7)) {
//			// fix for ie 6?
//		} else {
//			document.getElementById('modalWindowSmall').style.top = newPosition1 + "px";
//		}
//	});
	
	
/* -----------------------------  document ready ----------------------------------------- */
	$(document).ready(function(){
		
		swapImagesInput('.quicklookHeader .quicklookListsBtn','products/product_list_add_black_bg_btn','gif');
		swapImages('.quicklook_prod_detail_link .quicklook_prod_detail_btn','overlay/quicklook_prod_detail_btn','gif');
		
	
		$('.quicklookHeader .productThListBtn').click( function() {
			$('.productThListMenu').hide();
			//$(this).parent().find('.productThListMenu').css('display','block');
			$(this).parent().find('.productThListMenu').fadeIn('normal');
		});
		
		$('.quicklookHeader .productThListMenu').hover( 
			function() { $(this).show(); },
			function() { $('.productThListMenu').hide();}
		);
	});


}

var arrayOfProductsToCompare = [];

function findIndexInArray(argValue, argArray) {
	var returnValue = -1;
	for(var i=0;i < argArray.length; i++) {
		if (argValue == argArray[i]) {
			returnValue = i;
			break;
		}
	}
	
	return returnValue;
}

function toggleCompareCell(argElementID) {
	prodObj = document.getElementById(argElementID);
	
	if (prodObj.className == "selected") {
		prodObj.className = "unselected";
		
		var elementIndex = findIndexInArray(argElementID, arrayOfProductsToCompare)
		if (elementIndex != -1) {
			arrayOfProductsToCompare.splice(elementIndex, 1);
		}
	} else {
		if (arrayOfProductsToCompare.length < 4) {
			prodObj.className = "selected";
			arrayOfProductsToCompare.push(argElementID);
		} else {
			alert("You can only select 4 items to compare.");
		}
	}
	
	document.getElementById("selectedCount").innerHTML = arrayOfProductsToCompare.length;
	//alert(arrayOfProductsToCompare);
	
	if (arrayOfProductsToCompare.length > 1 && arrayOfProductsToCompare.length <= 4) {
		var htmlStr = "<a href=\"/profile/compare.aspx?ids=";
		htmlStr = htmlStr + arrayOfProductsToCompare;
		if (newQS != "") {
			htmlStr = htmlStr + "&" + newQS;
		}
		
		htmlStr = htmlStr + "\"><img src=\"/assets/images/compareSelectedBtn.gif\" onmouseover=\"this.src='/assets/images/compareSelectedBtn_over.gif'\" onmouseout=\"this.src='/assets/images/compareSelectedBtn.gif'\" alt=\"Compare\" title=\"Compare\" /></a>";
	} else {
		var htmlStr = "<img src=\"/assets/images/compareSelectedBtn_over.gif\" alt=\"You need to select at least 2 items to compare.\" title=\"You need to select at least 2 items to compare.\" />";
	}
	
	document.getElementById("compareAction").innerHTML = htmlStr;
}

