var userOmni ="";
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('/Characters') + 11).split('&');
    //var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        //alert(hash[0]+" >> "+hash[1]);
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function getUrlForCharacters()
{
   
    var hashes = window.location.href.slice(window.location.href.indexOf('/Characters') + 11);
   	
   	var splitAt=".";
   	var characterName=hashes;
   	if(hashes.indexOf(splitAt)>-1)
   	{
   		var varsArray = hashes.split(splitAt)
   		characterName=varsArray[0];
   	}
   	if(characterName.indexOf("/")>-1)
   	{
   		
   		var varArray=characterName.split("/");
   		//alert(varArray[1]);
   		characterName=varArray[1];
   	}

   	return characterName;
}
function findimg()
{

 var imgs,i;
// loop through all images of the document
 imgs=document.getElementsByTagName('img');
 for(i=0;i<imgs.length;i++)
 {
// test if the class 'roll' exists
  if(/roll/.test(imgs[i].className))
  {

// add the function roll to the image onmouseover and onmouseout and send
// the image itself as an object
   imgs[i].onmouseover=function(){roll(this);};
   imgs[i].onmouseout=function(){roll(this);};
  }
 }
}


function roll(o){
 var src,ftype,newsrc;
 // get the src of the image, and find out the file extension
 
 if (!$(o).parent().parent().hasClass('selected_character')){	
		 src = o.src;
		 ftype = src.substring(src.lastIndexOf('.'), src.length);
		 // check if the src already has an _on and delete it, if that is the case 
		 if(/_on/.test(src)){
		  newsrc = src.replace('_on','');
		  $(o).removeClass('on');
		  }else{
		  // else, add the _on to the src 
		  newsrc = src.replace(ftype, '_on'+ftype);
		  $(o).addClass('on');
		  }
		 o.src=newsrc;
	}

}


function downloadFlash(link){  //required jquery and colorbox js/css
	$('#legal #agree').attr('href',link);
	$.fn.colorbox({width:'50%',open:true, inline: true, href:'#legal'});return false;
}

/*function downloadIt(link){
	$.fn.colorbox.close(); 
	document.location = link;
}*/

function downloadIt(link)
{
	$.fn.colorbox.close(); 
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
}
/* ############# START OF Logic for tracking logeed in user ###################*/
function userTrack(name) 
{
		var nameEQ1 = 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(nameEQ1) == 0) 
			{	
				return  c.substring(nameEQ1.length,c.length);
			}
		}
		return false;
	}
var user = userTrack("userName");
if(user)
{
	userOmni="PAINTHEGAME/"+user;
}
/* ############# END OF Logic for tracking logeed in user ###################*/

