var newwindow = '';
var currSong = '';

function customInitSearchbox() {
	var currSelection = 'titleKeywords';
	$("#searchbox input.txt").each( function() { 
		if (typeof($(this).attr("value")) != "undefined") {
			currSelection = $(this).attr("class").replace(/txt /,"") ;
		}
	}) ;
	$("#searchbox select").each( function() { 
		if (this.selectedIndex != "0") {
			currSelection = $(this).attr("class") ;
		}
	}) ;
	$("#searchbox").css("height","32px").css("background","transparent url(/images/site/searchbox-bg-js.png) no-repeat right bottom") ;
	$("#searchbox label").css("position","absolute").css("left","300px").css("margin","0").css("padding-top","30px").css("height","0").css("overflow","hidden").css("color","#ffffff").css("width","30px").text("for").css("background","transparent") ;
	$("#searchbox input.txt, #searchbox select").css("position","absolute").css("left","314px").css("top","4px").css("margin","0").css("width","233px") ;
	$("#searchbox div").css("display","none").css("z-index","1") ;
	$("#searchbox input.btn").css("right","9999px").css("width","1px") ;
	$("#searchbox #" + currSelection).css("display","block").css("z-index","5") ;				
	$("#content-main").css("margin-top","60px") ;
	$("#searchbox form").prepend('<label class="searchby" for="searchChoice">Search by</label><select class="searchby" name="searchChoice"><option value="titleKeywords">Title</option><option value="lyricKeywords">Lyrics</option><option value="writerSelect">Writer</option><option value="themeSelect">Theme</option></select>') ;
	$("#searchbox label.searchby").css("margin","0").css("position","absolute").css("left","110px").css("color","#ffffff").css("width","70px").css("background","transparent").css("padding-top","30px").css("height","0").css("overflow","hidden") ;
	switch (currSelection) {
		case "lyricKeywords":
			$("#searchbox select.searchby").get(0).selectedIndex = 1 ;
			break ;
		case "writerSelect":
			$("#searchbox select.searchby").get(0).selectedIndex = 2 ;
			break ;
		case "themeSelect":
			$("#searchbox select.searchby").get(0).selectedIndex = 3 ;
			break ;
		default:
			$("#searchbox select.searchby").get(0).selectedIndex = 0 ;
			break ;
	} ;
	$("#searchbox select.searchby").css("margin","2px 0 0 0").css("position","absolute").css("left","155px").css("top","2px").css("width","125px").change( function() {
		var nextSelection = $(this).attr("value") ;
		$("#searchbox #" + currSelection).css("display","none").css("z-index","1") ;
		var testSelect = $("select." + currSelection).get(0) ;
		if (typeof(testSelect) != 'undefined') {
			testSelect.selectedIndex = 0 ;
		} else {
			$("input." + currSelection).attr("value","") ;
		}
		$("#searchbox #" + nextSelection).css("display","block").css("z-index","5") ;
		currSelection = nextSelection ;
	}) ;
	$("#searchbox select").not(".searchby").change( function() {
		$("#searchbox .btn").click() ;
	}) ;
}

function customPupWin(url) {
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'musicplayer','height=100,width=350');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

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 var 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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}