/* ************************** */
/* ************************** */
/* BEGIN THEME SWITCHING CODE */
/* ************************** */
/* ************************** */

var agt=navigator.userAgent.toLowerCase(); 
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1)); 
var is_nav3 = (is_nav && (parseInt(navigator.appVersion) == 3)); 
var is_nav4 = (is_nav && (parseInt(navigator.appVersion) == 4)); 
var is_nav4up = (is_nav && (parseInt(navigator.appVersion) >= 4)); 
var is_nav5up = (is_nav && (parseInt(navigator.appVersion) >= 5)); 
var is_ie   = (agt.indexOf("msie") != -1); 
var is_ie3  = (is_ie && (parseInt(navigator.appVersion) < 4)); 
var is_ie4  = (is_ie && (agt.indexOf("msie 4")!=-1)); 
var is_ie4up  = (is_ie  && (parseInt(navigator.appVersion) >= 4)); 
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4); 
var is_mac    = (agt.indexOf("mac")!=-1);
var is_ie50   = (is_ie && (agt.indexOf("msie 5.0")!=-1));

if (is_nav4) {
    alert('The browser you are using has become obsolete and will not be able to display this website correctly. Please upgrade your browser to the latest version to access this website.');
}

var pickup_msg="If you wish your order to be picked up instead of shipped, please let us know by clicking on the 'Add special instructions to seller' when you check out. We'll refund your shipping charge and contact you about picking it up.";



function setActiveStyleSheet(title) {
  var i, a, main;
	if (is_ie5up || is_nav5up)
	  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		  a.disabled = true;
		  if(a.getAttribute("title") == title) a.disabled = false;
		}
	  }
	else if (is_ie4)
	  for(i=0; (a = document.all.tags("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		  a.disabled = true;
		  if(a.getAttribute("title") == title) a.disabled = false;
		}
	  }
  createCookie("style", title, 365);
}

function getActiveStyleSheet() {
  var i, a;
	if (is_ie5up || is_nav5up)
	  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	  }
	else if (is_ie4)
	  for(i=0; (a = document.all.tags("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
	if (is_ie5up || is_nav5up)
	  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
		   && a.getAttribute("rel").indexOf("alt") == -1
		   && a.getAttribute("title")
		   ) return a.getAttribute("title");
	  }
	else if (is_ie4)
	  for(i=0; (a = document.all.tags("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
		   && a.getAttribute("rel").indexOf("alt") == -1
		   && a.getAttribute("title")
		   ) return a.getAttribute("title");
	  }
  return null;
}

function setTune(tuneNum) {

    if (is_ie4 || is_nav4) {
        alert('Music is not available with this browser. Please upgrade to a newer version.');    
    } else if (parent.tuneframe) {
        var isTune1on=document.getElementById("mhtune1on");
        var isTune2on=document.getElementById("mhtune2on");
        var isTune3on=document.getElementById("mhtune3on");
    
        // C01 begin: is there another tune playing? if so, turn off indicator
        if (tuneNum == 1 && isTune2on != null) {
            document.getElementById('mhtune2on').id='mhtune2';
        }
        else if (tuneNum == 1 && isTune3on != null) {
            document.getElementById('mhtune3on').id='mhtune3';
        }
        else if (tuneNum == 2 && isTune1on != null) {
            document.getElementById('mhtune1on').id='mhtune1';
        }
        else if (tuneNum == 2 && isTune3on != null) {
            document.getElementById('mhtune3on').id='mhtune3';
        }
        else if (tuneNum == 3 && isTune1on != null) {
            document.getElementById('mhtune1on').id='mhtune1';
        }
        else if (tuneNum == 3 && isTune2on != null) {
            document.getElementById('mhtune2on').id='mhtune2';
        }
        // C01 end
        // C02 begin: shuts off current tune, if desired
        tune_name='ghost.html';
        if (tuneNum == 1 && isTune1on != null && document.getElementById('mhtune1on')) {
            document.getElementById('mhtune1on').id='mhtune1';
            parent.tuneframe.document.location='/sounds/'+tune_name+'.html';
            createCookie("tune", 0, 365);
        }
        else if (tuneNum == 2 && isTune2on != null && document.getElementById('mhtune2on')) {
            document.getElementById('mhtune2on').id='mhtune2';
            parent.tuneframe.document.location='/sounds/'+tune_name+'.html';
            createCookie("tune", 0, 365);
        }
        else if (tuneNum == 3 && isTune3on != null && document.getElementById('mhtune3on')) {
            document.getElementById('mhtune3on').id='mhtune3';
            parent.tuneframe.document.location='/sounds/'+tune_name+'.html';
            createCookie("tune", 0, 365);
        }
        else if (tuneNum != 0 && document.getElementById('mhtune'+tuneNum)) {
            document.getElementById('mhtune'+tuneNum).id='mhtune'+tuneNum+'on';
            tune_name='estilo_tune'+tuneNum;
            parent.tuneframe.document.location='/sounds/'+tune_name+'.html';
            createCookie("tune", tuneNum, 365);
        }
        // C02 end
        bsndflag=true;
    }
}

function getActiveTune() {
	var isTune1on=document.getElementById("mhtune1on");
	var isTune2on=document.getElementById("mhtune2on");
	var isTune3on=document.getElementById("mhtune3on");
	var currentTune;
	if (isTune1on != null) {
		currentTune="1";
	}
	else if (isTune2on != null) {
		currentTune="2";
	}
	else if (isTune3on != null) {
		currentTune="3";
	}
	return currentTune;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
    var cookie = readCookie("style");
    var title = cookie ? cookie : getPreferredStyleSheet();
    setActiveStyleSheet(title);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

if (!(is_ie4 || is_nav4)) {
    var bsndflag=false;
    playMusic();
}

function playMusic() {
    if (!bsndflag) {
        var cookie2 = readCookie("tune");
        if (cookie2) {
            setTune(cookie2);
        } else {
            setTune('1');
        }
        setTimeout("playMusic()",300);
    } else {
        clearTimeout();
    }
}

if (screen.height <= 480) {
	var isBars = 'yes';
	var winHeight = '400';
	}
else if (screen.height <= 640) {
	var isBars = 'yes';
	var winHeight = '500';
	}
else {
	var isBars = 'no';
	var winHeight = '640';
	}

function popWin(loc,winDim,zoom_win,sizable)
	{
		var t = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+isBars+",resizable="+sizable+","+winDim+"";
		popupWin = window.open(loc,""+zoom_win+"",t);
		popupWin.focus();
	}

function popWinScroll(loc,winDim,zoom_win,sizable)
	{
		var t = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable="+sizable+","+winDim+"";
		popupWin = window.open(loc,""+zoom_win+"",t);
		popupWin.focus();
	}

function doUpMsg() {
    var do_pu_msg = readCookie("dopumsg");
    if (do_pu_msg!="1") {
    	alert(pickup_msg);
		createCookie("dopumsg", "1");
    }
}

function showCart() {
	doUpMsg();
	popupWin=popWin('https://www.paypal.com/cart/display=1&business=paypal%40estiloclothing.com&return=http%3A//www.estiloclothing.com/browse/thanks.html&cancel_return=http%3A//www.estiloclothing.com/browse/','width=600,height=400','paypal','yes');
}

