window.onscroll = moveCartConf;

function tracker (value) {
    if (navigator.userAgent.substring(0,9) >= "Mozilla/3") {
        this.value = value;
    }
}

myTracker = new tracker(null);

   

function pop_up(theURL) { //v2.0
    win = window.open(theURL,
		'',
		'toolbar=no,width=250,height=300,directories=no,statusbar=no,scrollbars=yes,resizeable=0,menubar=no,location=no,copyhistory=no'
		); 
    win.caller=this;
    
    win.focus();
} 

function NewWindow(mypage, myname, w, h, scrll) { 
	var winl = (screen.width - w) / 2; 
	var wint = (screen.height - h) / 2; 
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrll+',resizable' 
	win = window.open(mypage,myname,winprops) 
	if (parseInt(navigator.appversion) >=4) {win.window.focus(); } 
} 


var big = true;

function detectsize(){


	if (screen.width < 1024){
		big = false;
	}

}

detectsize();


var remote=null;
function rs(n,u,width,height,top,left) {
    args="width="+width+",height="+height+",resizable=no,scrollbars=no,status=0";
    remote=window.open(u,n,args);
    if (remote != null) {
	if (remote.opener == null)
	    remote.opener = self;
    }
    if ( top & left ){
	remote.moveTo(left,top);
	
    }
}


//this popup and focus function is for the  Back To School promo
function popup() {
	window.location.reload( false );

    popup=open('syllabusmain.htm','window2','resizable=no,width=900,height=595');
    if (popup.opener == null) popup.opener = self;
	
}

function focusOpener() {
    if (!opener.closed) {
        opener.focus();
    }
}

function launchSurchargeWin() {
  win = window.open("/checkout/surcharge.cfm", "surcharge","toolbar=no,width=350,height=160,directories=no,status=no,scrollbars=no,resize=no,menubar=no,location=no,copyhistory=no");
  win.caller = this;
  if (navigator.userAgent.substring(0,9) >= "Mozilla/4") {
	 win.moveTo(0,0);
  }
  win.focus();
}

function sb_check(){
	if(MusicStore.webPageAPISupported())
		return "1";
	else
		return "0";
}

function clr_text(inpt){
	if(inpt.value == "Search" && (inpt.style.color == "rgb(191, 191, 191)" || inpt.style.color.toUpperCase() == "#BFBFBF")){
		inpt.value = "";
		inpt.style.color = "#000000";
	}
}
function add_text(inpt){
	if(inpt.value == ""){
		inpt.style.color = "#BFBFBF";
		inpt.value = "Search";
	}
}
function adjustHeights(){
	column = document.getElementById('bot_tall');
	column.style.height = 'auto';
	h = column.offsetHeight;
	h = h - 10; //subtract padding height to make divs match exactly
	document.getElementById('bot_short').style.height = h + "px";
}

function newAjaxObject(){
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				return false;
			}
		}
	}
	return xmlHttp;
}

function addCartItem(pid, fi){
	pid = pid.toUpperCase();
	document.getElementById("loading_spinner").style.visibility = "visible";
	document.getElementById("loading_spinner").src = "/images_main/loading.gif"; //must reload the image source each time otherwise IE6 kills the gif animation
	var request = newAjaxObject();
	request.onreadystatechange=function(){
		if(request.readyState == 4){
			document.getElementById("loading_spinner").style.visibility = "hidden";
			result_array = eval(request.responseText);
			document.getElementById("cartItems").innerHTML = result_array[0];
			document.getElementById("cartAmt").innerHTML = result_array[1];
			if(result_array[2].length > 0){
				price = result_array[2];
				format = result_array[3];
				cover_src = "/images_main/pixel.gif";
				if(result_array[5] == 1) //if a coverart img exists for this product
					cover_src = "/annex/covers/" + pid + ".gif";
				document.getElementById("conf_cover").src = cover_src;
				conf_html = "$" + price + " " + format + "<br />added to cart";
				document.getElementById("cart_conf_msg").innerHTML = conf_html;
				Effect.Appear("cart_conf");
				if(typeof(disappear) != "undefined")
					clearTimeout(disappear);
				disappear = setTimeout("hideCartConf()", 3000);
				if(result_array[4] != ""){
					add_location = result_array[4];
					pageTracker._trackEvent('Add to Cart', add_location);
				}
			}
		}
	}
	url = "/ascripts/add_cart_item.php";
	url += "?pid=" + pid;
	if(fi > 0)
		url += "&fi=" + fi;
	request.open("POST", url, true);
	request.send(null);
}

function hideCartConf(){
	Effect.Fade("cart_conf");
}

function moveCartConf(){
	if(document.getElementById("cart_conf") != undefined){
		offsets = document.viewport.getScrollOffsets(); //using prototype.js viewport object
		window_top = offsets.top;
		if(window_top > 260){
			new_top = window_top + 5;
			document.getElementById("cart_conf").style.top = new_top + "px";
		}
		else{
			document.getElementById("cart_conf").style.top = "265px";
		}
	}
}


// Make IE6 respect css hover on the nav menu LIs
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
	
	$$(".addhover").each(function (s) {
		s.onmouseover = function() {
			this.addClassName('onhover');
		};
		s.onmouseout = function() {
			this.removeClassName('onhover');
		};
	});
}

function ship_pop_up(theURL) { //v2.0
    win = window.open(theURL,
		'',
		'toolbar=no,width=550,height=150,directories=no,statusbar=no,scrollbars=yes,resizeable=0,menubar=no,location=no,copyhistory=no'
		); 
    win.caller=this;
    
    win.focus();
} 

