itemgetrandom=function(){//picks a random number then unhides the item
	//if(!document.getElementById('i_preview')||document.getElementById('article_view')||document.getElementById('item_view')||document.getElementById('in_this_issue')||document.getElementById('sl_rates'))return;
	if(!document.getElementById('i_preview'))return;
	var r, founditem=false, e=document.getElementById('i_preview').childNodes;
	for(var i=0;i<e.length;i++){
		if(e[i].className=='content'){
			e=e[i].childNodes;
			break;
		}
	}
	while(founditem==false){
		r=Math.round(Math.random()*6);
		
		if(e[r]&&e[r].className=='item'){
			document.getElementById('i_preview').style.display='block';
			e[r].style.display='block';
			founditem=true;
		}
	}
}

articlegetrandoms=function(){//populates 2 extra article areas randomly
	if(document.getElementById('a_preview'))articlegetrandomssecondary();return;
	if(!document.getElementById('a_preview_home1'))return;
	var ou='',r, founditem=2, headertext='', foundfirst=-1, e=document.getElementById('a_preview_home1').childNodes;
	for(var i=0;i<e.length;i++){
		if(e[i].className=='header'){
			if(e[i].childNodes[0])headertext=e[i].childNodes[0].innerHTML;
		}
		if(e[i].className=='content'){
			e=e[i].childNodes;
		}
	}
	while(founditem<4){
		r=Math.round(Math.random()*10);
		if(typeof e[r]!='undefined'&&r!=foundfirst&&String(e[r].innerHTML)!='undefined'){
			if(document.getElementById('a_preview_home'+founditem)){
				ou='<div class="header"><h1>'+headertext+'</h1></div>';
				ou+='<div class="content">'+e[r].innerHTML+'</div>';
				ou=ou.replace(/h3>/gi,'h4>');
				document.getElementById('a_preview_home'+founditem).innerHTML=ou;
			}
			founditem++;
			foundfirst=r;
		}
	}
	
}

articlegetrandomssecondary=function(){
	var r, founditem=false,e=document.getElementById('a_preview').childNodes;
	for(var i=0;i<e.length;i++){
		if(e[i].className=='header'){
			if(e[i].childNodes[0])headertext=e[i].childNodes[0].innerHTML;
		}
		if(e[i].className=='content'){
			e=e[i].childNodes;
		}
	}
	
	while(founditem==false){
		r=Math.round(Math.random()*10);
		
		if(e[r]&&e[r].className=='item'){
			document.getElementById('a_preview').style.display='block';
			e[r].style.display='block';
			founditem=true;
		}
	}
}

categoryget=function(){
	if(document.getElementsByTagName('select').length==0)return;
	var h2,e=document.getElementsByTagName('select');
	for(var i=0;i<e.length;i++){
		if(e[i].name=='cat'){
			h2=e[i].options[e[i].selectedIndex].text;
			h2=h2.replace('--','');
			if(h2.toLowerCase()!='view all'&&h2.replace(/ /g,'')!=''){
				document.getElementById('h2_cat').innerHTML=h2;
				document.getElementById('h2_cat').style.visibility='visible';
			}
			break;
		}
	}
}

setcurrentfield=function(){
	if(document.forms.length>0){
		for(var i=0;i<document.forms[0].elements.length;i++){
			if(document.forms[0].elements[i].type=='text'||document.forms[0].elements[i].type=='textarea'){
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

var searchformidx;
searchcheck=function(){
	if(document.forms[searchformidx].elements[0].value==''){
		alert('Please enter a search phrase.');
		document.forms[searchformidx].elements[0].focus();
		return false
	}else{
		return true
	}
}

searchattachcheck=function(){
	for(var i=0;i<document.forms.length;i++){
		if(document.forms[i].name=='search'){
			searchformidx=i;
			document.forms[i].onsubmit=function(){return searchcheck()}
		}
	}
}

formstyle=function(){
	//attach correct styles
	var f;
	for(var i=0;i<document.forms.length;i++){
		f=document.forms[i];
		for(var a=0;a<f.elements.length;a++){
			if(f.elements[a].tagName.toLowerCase()=='input')f.elements[a].className=f.elements[a].type.toLowerCase();
		}
		document.forms[i].style.visibility='visible';
	}
}

bannercheck=function(){
	var e=document.getElementsByTagName('div');
	for(var i=0;i<e.length;i++){
		if(e[i].className=='ad')alert(e[i].innerHTML);
	}
}

menuadjust=function(){
	//remove "win" from dropdown and adjust last menu item's class to remove the separator
	var m=document.getElementById('main_menu');
	var ms=m.getElementsByTagName('a');
	for(var i=0;i<ms.length;i++){
		if(ms[i].innerHTML.indexOf('Win')>-1){
			ms[i].style.display='none';
			break;
		}
	}
	for(var i=ms.length-1;i>=0;i--){
		if(ms[i].className=='item1'){
			ms[i].className+=' last';
			break;
		}
	}
}

init=function(){
	categoryget();
	formstyle();
	itemgetrandom();
	//bannercheck();
	articlegetrandoms();
	setcurrentfield();
	searchattachcheck();
	menuadjust();
}

DropDownMenuX=function(id) {
	this.id=id;
	this.position = {
		"level1": { "top": 0, "left": 0},
		"levelX": { "top": 0, "left": 0}
	}
	
	var hidetimeout=400;
	
	this.delay = {
		"show": 0,
		"hide": 400
	}
	
	this.init=function(){
		var links=document.getElementById(this.id).getElementsByTagName('a');
		for(var i=0;i<links.length;i++){
			if(links[i].offsetParent&&links[i].offsetParent.className!='section'){//parse the div next to the a element
				links[i].onmouseover=function(){dropdownshow(this.nextSibling)};
				links[i].onmouseout=function(){dropdownhideinitiate(this.nextSibling)};
			}else{//parse the div that is the parent of the a element
				links[i].onmouseover=function(){dropdownshow(this.offsetParent)};
				links[i].onmouseout=function(){dropdownhideinitiate(this.offsetParent)};
			}
		}
	}
	
	dropdownshow=function(el){
		clearTimeout(timerdropdownhide);
		if(dropdowntohide)dropdownhide();
		if(!el)return;
		if(el.innerHTML.replace(/[ \n]/g,'')=='')return;//don't show empty div elements
		el.style.display='block';
	}
	
	var timerdropdownhide,dropdowntohide;
	dropdownhideinitiate=function(el){
		clearTimeout(timerdropdownhide);
		if(!el)return;
		dropdowntohide=el;
		timerdropdownhide=setTimeout(dropdownhide,self.delay.hide);
	}
	
	dropdownhide=function(){
		if(!dropdowntohide)return;
		dropdowntohide.style.display='none';
		dropdowntohide=null;
	}
	
	var self = this;
}

searchBoxes=function() {
	var cb1 = document.getElementById("all")
	//var cb2 = document.getElementById("sq_is_pages")
	var cb3 = document.getElementById("sq_is_articles")
	var cb4 = document.getElementById("sq_is_items")
	var cb5 = document.getElementById("sq_is_items2")
	
	//if (cb2.checked || cb3.checked || cb4.checked || cb5.checked)
	if (cb3.checked || cb4.checked || cb5.checked)
		cb1.checked = false;
	else
		cb1.checked = true;
}
searchBoxesALL=function() {
	var cb1 = document.getElementById("all")
	//var cb2 = document.getElementById("sq_is_pages")
	var cb3 = document.getElementById("sq_is_articles")
	var cb4 = document.getElementById("sq_is_items")
	var cb5 = document.getElementById("sq_is_items2")
	
	if(cb1.checked) {
		//cb2.checked = false;
		cb3.checked = false;
		cb4.checked = false;
		cb5.checked = false;
	}
}

launchPlay=function(ic_id, jumpToSong) {
	// Category
	var qString = "playlist.php";
	if(ic_id) qString = "playlist.php?cat=" + ic_id + "&jts=" + jumpToSong;
	
	// Window
	var settings = "width=486,height=202,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,top=50,left=50";
	var oNewWindow = window.open(qString, "SLMagPlayer", settings, false);
}