var dloc = document.location.href + '';
if(dloc.charAt(8) != 'w') document.location = 'http://www.' + dloc.substring(dloc.indexOf('fiql.com'), dloc.length);
 
walkDivs = document.getElementsByTagName('div');
	
function checkBrowser()
{
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()
function upDown(div,nest)
{
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	if(obj.display=='block') obj.display='none'
	else obj.display='block'
}

function displayBrowse(x)
{
	document.getElementById('browseBlock').style.display = x;
}

inDelay = 0;

function browseOver()
{
	if(document.getElementById('searchField')){
		document.getElementById('searchField').blur();
		document.getElementById('searchField').value='';
	}
	maxBrowse();
}

function browseOut()
{
	if(!inDelay) outDelay = setTimeout("minBrowse()",50);
	inDelay = 1;
}

function keepBrowse()
{
	if(inDelay) {
		clearTimeout(outDelay);
		inDelay = 0;
	}
}

var currentWidth = 0;
var currentHeight = 0;
var maxWidth = 450;
var maxHeight = 300;

function maxBrowse()
{
	var browseOutline = document.getElementById('browseOutline');
	browseOutline.style.background = '#FFF';
	browseOutline.style.display = 'block';
	currentWidth = currentWidth + Math.floor(maxWidth/5);
	currentHeight = currentHeight + Math.floor(maxHeight/5);
	browseOutline.style.width = currentWidth + 'px';
	browseOutline.style.height = currentHeight + 'px';
	if(currentWidth < maxWidth) setTimeout('maxBrowse()',20);
	else {
		browseOutline.style.display = 'none';
		displayBrowse('block');
	}
}

function minBrowse()
{
	var browseOutline = document.getElementById('browseOutline');
	browseOutline.style.background = 'transparent';
	displayBrowse('none');
	browseOutline.style.display = 'block';
	currentWidth = currentWidth - Math.floor(maxWidth/6);
	currentHeight = currentHeight - Math.floor(maxHeight/6);
	currentWidth = (currentWidth > 0) ? currentWidth : 0;
	currentHeight = (currentHeight > 0) ? currentHeight : 0;
	browseOutline.style.width = currentWidth + 'px';
	browseOutline.style.height = currentHeight + 'px';
	if(currentWidth > 10) setTimeout('minBrowse()',20);
	else {
		browseOutline.style.display = 'none';
		currentWidth = 0;
		currentHeight = 0;
	}
}

var autoFocus = '';


function addOnLoadEvent(onloadToAdd){
 var prevOnLoad = window.onload;
 if(typeof window.load != 'function'){
  window.onload = onloadToAdd;
 } else {
  window.onload = function(){
   if(prevOnLoad){
    prevOnLoad();
   }
   onloadToAdd();
  }
 }
}


function ol()
{
	af = autoFocus ? autoFocus : 'none';
	if (af!='none' && document.getElementById(af)) document.getElementById(af).focus();
	if (document.getElementById('loading')){
		document.getElementById('loading').style.display='none';
		document.getElementById('pageContent').style.display='block';
	}
}
function setLiveList() {
 if(readCookie('liveListState') && $('live-list')) {
  if(readCookie('liveListPosX')) {
   $('live-list').style.left = readCookie('liveListPosX');
   $('live-list').style.top = readCookie('liveListPosY');
  }
  if(readCookie('liveListState') == 'open') openLiveList();
 }
}

addOnLoadEvent(ol);

var tFlag = 1;

function timeToKill()
{
	killMenu = setTimeout("closeMenus()",150);
	tFlag = 0;
}

function keepAlive()
{
	if(!tFlag){
		clearTimeout(killMenu);
		tFlag = 1;
	}
}

menuOpen = 0;

function openMenu(n)
{
	closeMenus();
	document.getElementById(n).style.display = 'block';
	menuOpen = document.getElementById(n);
}

function closeMenus()
{
	if(menuOpen){
		menuOpen.style.display = 'none';
		menuOpen=0;
	}
}

function changeSel(n,v)
{
	document.getElementById('searchPulldown').innerHTML = n;
	document.getElementById('searchSection').value = v;
	closeMenus();
}

pickDelay = 0;

function showPick(p)
{
	pickDelay = setTimeout("showPickOpen('"+p+"')",350);
}

function clearPickDelay()
{
	if(pickDelay){
		clearTimeout(pickDelay);
		pickDelay = 0;
	}
}

pickOpen = 0;

function showPickOpen(p)
{
	hidePicks();
	document.getElementById(p).style.display = 'block';
	pickOpen = document.getElementById(p);
}

function hidePicks()
{
	if(pickOpen){
		pickOpen.style.display = 'none';
		pickOpen = 0;
	}
}

closeTime = 0;
function closeSort()
{
	if(closeTime)
	{
		document.getElementById('sortMenu').style.display = 'none';
	}
	else
	{
		closeSortMenu = setTimeout("closeSort()", 250);
		closeTime = 1;
	}
}
function keepSort()
{
	if(closeTime)
	{
		clearTimeout(closeSortMenu);
		closeTime = 0;
	}
}
function openSort()
{
	document.getElementById('sortParent').blur();
	document.getElementById('sortMenu').style.display = 'block';
}
function changeSort()
{
	document.getElementById('sortParent').innerHTML = 'Sorting...';
	document.getElementById('sortMenu').style.display = 'none';
	closeTime = 0;
}

function termsWin(){
 termswindow = window.open('/terms.php','terms','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=600,height=400');
}


posx = 0;

function caps(str)
{
 newStr = '';
 for(i=0; i<str.length; i++) {
  pc = i ? str.charAt(i-1) : ' ';
  if(pc == '_' || pc == ' ' || pc == '-' || pc == '/' || pc == '(' || pc == '[' || pc == '{' || pc == '.' || pc == '"' )
   newStr += str.charAt(i).toUpperCase();
  else
   newStr += str.charAt(i).toLowerCase();
 }
 return newStr;
}

function getPos(e) {
 posx = 0;
 posy = 0;
 if (!e) var e = window.event;
 if (e.pageX || e.pageY)  {
  posx = e.pageX;
  posy = e.pageY;
 }
 else if (e.clientX || e.clientY)  {
  posx = e.clientX + document.body.scrollLeft
   + document.documentElement.scrollLeft;
  posy = e.clientY + document.body.scrollTop
   + document.documentElement.scrollTop;
 }
}

function popTags(playlistId) {	
 
	var popped = document.getElementsByTagName("div");
 var elem = $('tagText_' + playlistId);
 
	for(i in popped) {
		if(popped[i].className == "myfiql-tag-pop") popped[i].style.display = 'none';
	}
	
	if(!elem)
		return false;
  
 elem.style.marginLeft = (posx - 502) + "px";
	var curstyle = elem.style.display;
	
	if(curstyle == 'block') {
		elem.style.display = 'none';
	} else {
		elem.style.display = 'block';
  document.getElementById('tagInput_' + playlistId).focus();
	}
	
	return;
}

function mouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}

function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;}

function findPos(obj) {
 curleft = curtop = 0;
 if (obj.offsetParent) {
  curleft = obj.offsetLeft
  curtop = obj.offsetTop
  while (obj = obj.offsetParent) {
   curleft += obj.offsetLeft
   curtop += obj.offsetTop
  }
 }
}

function openLiveList(evt) {
 if(!readCookie('liveListPosX')) {
  $('live-list').style.left = (parseInt(mouseX(evt)) - 200) + 'px';
  $('live-list').style.top = '185px';
 }
 $('live-list').style.display = 'block';
 createCookie('liveListState', 'open', 1000);
}

function closeLiveList() {
 $('live-list').style.display = 'none';
 createCookie('liveListState', 'closed', 1000);
}

function dragWindow(evt) {
 dragObj = $('live-list');
 curX = parseInt(mouseX(evt));
 findPos(dragObj);
 winOffsetX = curX - curleft;
 winOffsetY = 12;
 dragLock = 0;
 $('ll-drag-block').style.display = 'block';
 document.onmousemove = captureMouse;
}

function dropWindow() {
 dragLock = 1;
 document.onmousemove = '';
 $('ll-drag-block').style.display = 'none';
 createCookie('liveListPosX', dragObj.style.left, 1000);
 createCookie('liveListPosY', dragObj.style.top, 1000);
}

function captureMouse(evt) { 
 if(!dragLock) {
  m_x = parseInt(mouseX(evt));
  m_y = parseInt(mouseY(evt));
  dragObj.style.left = (m_x - winOffsetX) + 'px';
  dragObj.style.top = (m_y - winOffsetY) + 'px';
 }
}


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

descState = 0;
function swapDesc() {
 if(!descState) {
  $('short-desc').style.display = 'none';
  $('long-desc').style.display = 'block';
  descState = 1;
 }
 else {
  $('short-desc').style.display = 'block';
  $('long-desc').style.display = 'none';
  descState = 0; 
 }
}



