/* CONFIGURATION AREA */
/*
	browsers:
		IE - Microsoft Internet Explorer
		FF - FireFox
		Safari - Safari browser
		Opera - Opera browser
		all - includes IE, FF, Opera and Safari
		
	parentId:
		any existing Id attribute 
	tagName:
		any valid tag name
	tagPosition:
		all - all inner elements 
		children - first level children only
	className:
		any valid class name
*/

var browsers = 'all';
var config = {
	hovers: new Array(
		{
			parentId:'main-menu',
			tagName:'li',
			tagPosition:'children',
			className:'hover'
		}
	)
};

/* CODE AREA */

/* hovers */

var initHovers = function()
{
	for (var index in config.hovers){
		var conf = config.hovers[index];
		var topLevelElement = document.getElementById(conf.parentId);
		if (topLevelElement){
			var subElements = topLevelElement.getElementsByTagName(conf.tagName);
			for (var i = 0; i < subElements.length; i++){
				if (conf.tagPosition == 'all' || (conf.tagPosition == 'children' && subElements[i].parentNode.id == conf.parentId))
				{
					subElements[i].configIndex = index;
					subElements[i].onmouseover = function(){
						this.className += ' ' + config.hovers[this.configIndex].className;
					};
					subElements[i].onmouseout = function(){
						this.className = this.className.replace(config.hovers[this.configIndex].className,'');
					};
				}
			}
		}
	}
}

/* common */

var currentState = {};

var opera = window.opera;
var safari = navigator.appVersion.indexOf("Safari") != -1;
var ie = document.all && !window.opera;
var ff = navigator.userAgent.indexOf("Firefox") != -1;

var addEvent = function(browsers,event,initMethod)
{
	if (opera && (browsers.match(/Opera/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (safari && (browsers.match(/Safari/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (ie && (browsers.match(/IE/) || browsers.match(/all/))) {
		window.attachEvent("on" + event, initMethod);
	} else if (ff && (browsers.match(/FF/) || browsers.match(/all/))) {
		window.addEventListener(event, initMethod, false);
	} else if (!ie && !ff && !safari && !opera) {
		if (window.addEventListener){
			window.addEventListener(event, initMethod, false);
		}
		else if (window.attachEvent){
			window.attachEvent("on" + event, initMethod);
		}
	} 
}

$(document).ready(function(){
	initHovers();
	$('div.select ul').css('visibility','visible').hide();
	$('div.select input').hide();
	
	$('div.select span').click(function(){
		$(this).parents('div.select').find('ul').toggle();
	});
	$('div.select a').click(function(e){
		e.preventDefault();
		var curValue = $(this).text();
		$(this).parents('div.select').find('input').attr('value',curValue);
		$(this).parents('div.select').find('span').html(curValue);
		$(this).parents('div.select').find('ul').hide();
	});
	
	$('table tr').removeClass('dark');
	$('table tr').hover(
		function(){$(this).addClass('dark');},
		function(){$(this).removeClass('dark');}
	);
});



$(document).ready(function() {
  $("#sChartMonth").click(function(){
     $("#splashCharts").animate({ 
        marginLeft: "0px"
      }, 300 );
      
     $("#sChartMonth").animate({ 
        backgroundPosition: "0 -24px"
      }, 1 );
	  $("#sChartNew").animate({ 
        backgroundPosition: "0 0"
      }, 1 );
      $("#sChartAllTime").animate({ 
        backgroundPosition: "0 0"
      }, 1 );
    });

});

$(document).ready(function() {
  $("#sChartNew").click(function(){
     $("#splashCharts").animate({ 
        marginLeft: "-693px"
      }, 300 );
      
     $("#sChartNew").animate({ 
        backgroundPosition: "0 -24px"
      }, 1 );
	  $("#sChartMonth").animate({ 
        backgroundPosition: "0 0"
      }, 1 );
      $("#sChartAllTime").animate({ 
        backgroundPosition: "0 0"
      }, 1 );
    });

});

$(document).ready(function() {
  $("#sChartAllTime").click(function(){
     $("#splashCharts").animate({ 
        marginLeft: "-1386px"
      }, 300 );
      $("#sChartAllTime").animate({ 
        backgroundPosition: "0 -24px"
      }, 1 );
     $("#sChartMonth").animate({ 
        backgroundPosition: "0 0"
      }, 1 );
	  $("#sChartNew").animate({ 
        backgroundPosition: "0 0"
      }, 1 );
     
    });
});

$(document).ready(function() {
  $("#aChartMonth").click(function(){
     $("#chartsHolder").animate({ 
        marginTop: "0px"
      }, 300 );
    });
});

$(document).ready(function() {
  $("#aChartAllTime").click(function(){
     $("#chartsHolder").animate({ 
        marginTop: "-390px"
      }, 300 );
    });
});


function showPreview(id)
{	
	var strFeatures="toolbar=no,status=no,menubar=no,location=no"
	strFeatures=strFeatures+",scrollbars=no,resizable=no,height=450,width=400"

	var iplayer = document.getElementById('iplayer').innerHTML;
	
	if( iplayer == 1 ){
		fo.write("musicflash");
	}

	window.name = "main";
	newWin = window.open("/preview.php?id="+id,"TellObj",strFeatures);
       if (window.focus) {newWin.focus()}
}

function showPreviewD(id)
{	
	
	var iplayer = document.getElementById('iplayer').innerHTML;
	
	if( iplayer == 1 ){
		fo.write("musicflash");
	}

	var mygetrequest=new ajaxRequest()
	mygetrequest.onreadystatechange=function(){
	 if (mygetrequest.readyState==4){
	  if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
	   fop.write("mfplayer");
	  }
	  else{
	   alert("An error has occured making the request")
	  }
	 }
	}
	mygetrequest.open("GET", "http://www.crooklynclan.net/preview-beta.php?id="+id, true)
	mygetrequest.send(null);
	
}

function removeFromPlaylist(id)
{	
	
	var mygetrequest=new ajaxRequest()
	mygetrequest.onreadystatechange=function(){
	 if (mygetrequest.readyState==4){
	  if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
	   fop.write("mfplayer");
	  }
	  else{
	   alert("An error has occured making the request")
	  }
	 }
	}
	mygetrequest.open("GET", "http://www.crooklynclan.net/preview-beta.php?del="+id, true)
	mygetrequest.send(null);
	
}

function showVPreview(id)
{	
	var strFeatures="toolbar=no,status=no,menubar=no,location=no"
	strFeatures=strFeatures+",scrollbars=yes,resizable=no,height=340,width=400"
	
	window.name = "main";
	newWin = window.open("/previewvid.php?id="+id,"TellObj",strFeatures);

       if (window.focus) {newWin.focus()}
}

// display decision alert box
function decision(message, url){
	if(confirm(message)) location.href = url;
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, 'preview', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=200,height=20');");
}


function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
    //suppress error
   }
  }
 }
 else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  return new XMLHttpRequest()
 else
  return false
}


function popUpPromo(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, 'preview', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=693,height=500');");
}
