/*
CSS Browser Selector v0.3.5.1 (Feb 05, 2010) + iPad
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('ipad')?'ipad':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);



//========================
// General functions
//========================

function toggleVisibleElement(object) {
	$("#" + object).toggle();
}


function rdStat() {
	ls="/log____image.gif?summarylog&je="+navigator.javaEnabled()+"&sw="+screen.width+"&sh="+screen.height;

	if (screen.pixelDepth) ls+="&sd="+screen.pixelDepth;
	else if (screen.colorDepth) ls+="&sd="+screen.colorDepth;

	if (navigator.language) ls+="&la="+navigator.language;
	else if (navigator.userLanguage) ls+="&la="+navigator.userLanguage;

	var cookieEnabled = (navigator.cookieEnabled) ? true : false;
	if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
	{ 
		document.cookie="log____cc=1;path=/;";
		cookieEnabled = (document.cookie.indexOf("log____cc") != -1) ? true : false;
	}
	ls+="&co="+cookieEnabled;

	if (window.innerWidth) {
		ls+="&ww="+window.innerWidth;
		ls+="&wh="+window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		ls+="&ww="+document.documentElement.clientWidth;
		ls+="&wh="+document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientWidth) {
		ls+="&ww="+document.body.clientWidth;
		ls+="&wh="+document.body.clientHeight;
	}

	li=new Image();
	li.src=ls;
}



//========================
// Site Specific functions
//========================

function toggleSearchOptions() {
	if ($("#searchoptions").css("display") == 'none') {
		$("#searchoptions").slideDown("fast");
		$("a#showoptions").html("-");
	}
	else {
		$("#searchoptions").slideUp("slow");
		$("a#showoptions").html("+");
	}
}


function repeatSearch(st) {
	if (st == 'concise') {
		$("#searchType option:eq(0)").attr("selected", true);
	}
	else {
		$("#searchType option:eq(1)").attr("selected", true);
	}
	$("#quicksearch").submit();
}


function toggleSearchCriteria(theElement, theAction) {
	if (theAction == "add") {
		$("#"+theElement).css("visibility", "visible");
    }
    else if (theAction == "remove") {
		$("#"+theElement).css("visibility", "hidden");
 		$("#r2").val("");
    }
}


function changeSearchSection(o) {
	curValue = $(o).val();
	if (curValue == "cd") {
		$("#advanced1").css("visibility", "visible");
		$("#addcriteria").css("visibility", "visible");
		populate('cd');
    }
    else if (curValue == "classical") {
		$("#advanced1").css("visibility", "visible");
		$("#addcriteria").css("visibility", "visible");
		populate('classical');
    }
    else if (curValue == "dvd") {
		$("#advanced1").css("visibility", "visible");
		$("#addcriteria").css("visibility", "visible");
		populate('dvd');
    }
    else if (curValue == "hardware") {
		$("#advanced1").css("visibility", "visible");
		$("#advanced2").css("visibility", "hidden");
		$("#addcriteria").css("visibility", "hidden");
 		$("#r2").val("");
		populate('hardware');
   	}
    else if (curValue == "apparel") {
		$("#advanced1").css("visibility", "visible");
		$("#advanced2").css("visibility", "hidden");
		$("#addcriteria").css("visibility", "hidden");
 		$("#r2").val("");
		populate('apparel');
   	}
    else if (curValue == "book") {
		$("#advanced1").css("visibility", "visible");
		$("#addcriteria").css("visibility", "visible");
		populate('book');
   	}
    else {
		$("#advanced1").css("visibility", "hidden");
		$("#advanced2").css("visibility", "hidden");
		$("#addcriteria").css("visibility", "hidden");
 		$("#r1").val("");
 		$("#r2").val("");
		populate('');
    }
}


function toggleTips(o) {
	if ($(o).css("display") == 'none') {
		$(o).slideDown("slow");
	}
	else {
		$(o).slideUp("normal");
	}
}


function populate(o) {
	s1 = $("#q1");
	s2 = $("#q2");

	var mitems=new Array();
	mitems[''] = [];
	mitems['cd'] = ['Artist', 'artist', 'Album', 'title', 'Barcode', 'barcode'];
	mitems['classical'] = ['Work', 'title', 'Composer', 'composer', 'Conductor', 'artist', 'Performer', 'artist', 'Label', 'label', 'Barcode', 'barcode'];
	mitems['dvd'] = ['DVD Title', 'title', 'Artist', 'artist', 'Barcode', 'barcode'];
	mitems['hardware'] = ['Item Name', 'title'];
	mitems['apparel'] = ['Item Name', 'title', 'Artist', 'artist'];
	mitems['book'] = ['Book Title', 'title', 'Author', 'artist', 'ISBN', 'barcode'];

	cur = mitems[o];
	sdata = '';
	
	for (var i=0; i<cur.length/2; i++) {
		sdata += '<option value="' + cur[(i * 2) + 1] + '">' + cur[i * 2] + '</option>';
	}

	s1.empty();
	s1.html(sdata);

	s2.empty();
	s2.html(sdata);
}


function setupSlideshowLeaderboards(slideshow, fx, speed, delay, direction) {
	var fx = (fx == null) ? "fade" : fx;
	var speed = (speed == null) ? 1600 : speed;
	var delay = (delay == null) ? 8000 : delay;
	var direction = (direction == null) ? "down" : direction;
	$(slideshow).cycle({
		fx:			fx,
		speed:		speed,
		timeout:	delay,
		pause:		1,
		sync:		1,
		direction:	direction,
		slideExpr:	'div.leaderboard'
	});
}


function setupSlideshowButtons(slideshow, fx, speed, delay, direction) {
	var fx = (fx == null) ? "fade" : fx;
	var speed = (speed == null) ? 1600 : speed;
	var delay = (delay == null) ? 8000 : delay;
	var direction = (direction == null) ? "right" : direction;
	$(slideshow).cycle({
		fx:			fx,
		speed:		speed,
		timeout:	delay,
		pause:		1,
		sync:		1,
		direction:	direction,
		slideExpr:	'div.button'
	});
}


function setupSlideshowTowers(slideshow, fx, speed, delay, direction) {
	var fx = (fx == null) ? "fade" : fx;
	var speed = (speed == null) ? 1600 : speed;
	var delay = (delay == null) ? 8000 : delay;
	var direction = (direction == null) ? "right" : direction;
	$(slideshow).cycle({
		fx:			fx,
		speed:		speed,
		timeout:	delay,
		pause:		1,
		sync:		1,
		direction:	direction,
		slideExpr:	'div.tower'
	});
}


function showStores(o) {
	
	$("#uppernorth").css("display", "none");
	$("#lowernorth").css("display", "none");
	$("#uppersouth").css("display", "none");
	$("#lowersouth").css("display", "none");
	
	$(o).css("display", "block");
}


function getVisiblePageSize() {
	// borrowed from 
	// jQuery Lightbox
	// Version 0.5 - 11/29/2007
	// @author Warren Krewenki
	
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) { // all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}


	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
}



function setYouTubeSize(pageWidth, object) {
// using old embed method 16:9 dimensions are:
//	720x429, 480x294, 360x224
//
// using new iframe method 16:9 dimensions are:
// 720x435, 480x300, 360x232 (and to maximize space on mobile devices 460x288)

	if (pageWidth > 1160) {
		$(object + " object").css("height", 429).css("width", 720);
		$(object + " embed").css("height", 429).css("width", 720);
	}
	else if (pageWidth > 920) {
		$(object + " object").css("height", 294).css("width", 480);
		$(object + " embed").css("height", 294).css("width", 480);
	}
	else {
		$(object + " object").css("height", 224).css("width", 360);
		$(object + " embed").css("height", 224).css("width", 360);		
	}
}


function setYouTubeiFrameSize(pageWidth, object) {
// using new iframe method 16:9 dimensions are:
// 720x435, 480x300, 360x232 (and to maximize space on mobile devices 460x288)

	if (pageWidth > 1160) {
//		$(object).css("height", 435).css("width", 720);
		$(object).removeClass("youtubesmall").removeClass("youtubemedium").addClass("youtubelarge");
	}
	else if (pageWidth > 920) {
//		$(object).css("height", 300).css("width", 480);
		$(object).removeClass("youtubesmall").removeClass("youtubelarge").addClass("youtubemedium");
	}
	else {
//		$(object).css("height", 232).css("width", 360);
		$(object).removeClass("youtubemedium").removeClass("youtubelarge").addClass("youtubesmall");
	}
}


function prepGallery(i) {

	var iframeHref = "/_ajax/gallery.lsx?catalogID=" + i;
	var iframeHeight = 534;		
	var isBadIE = $.browser.msie && $.browser.version < 8;
	var isBrokenIE = $.browser.msie && $.browser.version < 7;

	if (isBadIE) {
		var iframeHeight = 560;
	} 

	if (isBrokenIE) {

	}
	else {
		$("a.zoom").colorbox({
			width:420, height: iframeHeight,
			initialHeight: 8, initialWidth: 8,
			href: iframeHref,
			opacity: 0.85,
			iframe: true,
			fastIframe: false,
			scrolling: false,
		    onOpen: function(){
      				$("#youtubeiframe").css({ "visibility": "hidden" });
	    	},
		    onClosed: function(){
				$("#youtubeiframe").css({ "visibility": "visible" });
		    }
		} );
	};
}


// ------------------------------------------------------
// For Checkout
// ------------------------------------------------------

function changeCheckoutAction(o, sct, ot) {
	if (o == "step1") {
		$("#a").val("update");
		$("#ns").val("1");
		$("#paymentdetails").css("display", "none");
		$("#updateorder").css("display", "block");
		$("#orderShipping").html(sct)
		$("#orderTotal").html(ot)
	}
	else if (o == "step2") {
		$("#a").val("update");
		$("#ns").val("2");
		$("#updateorder").css("display", "none");
		$("#paymentdetails").css("display", "block");
	}	
}


function hideButton(o) {
	if (o == "placeorder") {
		$("#placeorder").css("display", "none");
		$("#processing").css("display", "block");
	}
}


function showPaymentElement(o)
	{
	if (o == "Gift Card") {
		$("#gcDetails").css("display", "block");
    }
    else if (o == "Hampsta Card") {
		$("#hampstaDetails").css("display", "block");
    }
    else if (o == "Giftstation Card") {
		$("#gsDetails").css("display", "block");
    }
	else if (o == "Credit Card") {
		$("#ccDetails").css("display", "block");
    }
	else if (o == "ASB True Rewards") {
		$("#trDetails").css("display", "block");
    }
    else if (o == "Farmers Card") {
		$("#fcDetails").css("display", "block");
    }
    else if (o == "Q Card") {
		$("#qcDetails").css("display", "block");
    }
    else if (o == "Bank Transfer") {
		$("#banktransferDetails").css("display", "block");
    }
    else if (o == "MyMarbecks") {
		$("#myMarbecksDetails").css("display", "block");
    }
}	


function togglePaymentElement(o)
	{
	curValue = $(o).val();
	
	$("#gcDetails").css("display", "none");
	$("#hampstaDetails").css("display", "none");
	$("#gsDetails").css("display", "none");
	$("#ccDetails").css("display", "none");
	$("#trDetails").css("display", "none");
	$("#fcDetails").css("display", "none");
	$("#qcDetails").css("display", "none");
	$("#banktransferDetails").css("display", "none");
	$("#myMarbecksDetails").css("display", "none");
	
	if (curValue == "Gift Card") {
		$("#gcDetails").css("display", "block");
	}
    else if (curValue == "Hampsta Card") {
		$("#hampstaDetails").css("display", "block");
    }
	else if (curValue == "Giftstation Card") {
		$("#gsDetails").css("display", "block");
	}
	else if (curValue == "Credit Card") {
		$("#ccDetails").css("display", "block");
	}
	else if (curValue == "ASB True Rewards") {
		$("#trDetails").css("display", "block");
	}
    else if (curValue == "Farmers Card") {
		$("#fcDetails").css("display", "block");
    }
    else if (curValue == "Q Card") {
		$("#qcDetails").css("display", "block");
    }
	else if (curValue == "Bank Transfer") {
		$("#banktransferDetails").css("display", "block");
	}
	else if (curValue == "MyMarbecks") {
		$("#myMarbecksDetails").css("display", "block");
	}
}

