// JavaScript Document
$(document).ready(function() {
						   
if(club_is)
{
	a = -84; b = -150;
	switch(club_is)
	{
		case 'barca': 		$('.logo-slide').css("background-position", '0px 0px' );
					  		$('.name-slide').css("background-position", '0px 0px' ); 
							$('#logo-counter').text(1); break;
		case 'arsenal': 	$('.logo-slide').css("background-position", (1*a)+'px 0px' );
					 		$('.name-slide').css("background-position", (1*b)+'px 0px' ); 
							$('#logo-counter').text(2); break;
		case 'chelsea': 	$('.logo-slide').css("background-position", (2*a)+'px 0px' );
					 		$('.name-slide').css("background-position", (2*b)+'px 0px' ); 
							$('#logo-counter').text(3); break;
		case 'liverpool': 	$('.logo-slide').css("background-position", (3*a)+'px 0px' );
					 		$('.name-slide').css("background-position", (3*b)+'px 0px' ); 
							$('#logo-counter').text(4); break;
		case 'madrid': 		$('.logo-slide').css("background-position", (4*a)+'px 0px' );
					 		$('.name-slide').css("background-position", (4*b)+'px 0px' ); 
							$('#logo-counter').text(5); break;
		case 'manu': 		$('.logo-slide').css("background-position", (5*a)+'px 0px' );
					 		$('.name-slide').css("background-position", (5*b)+'px 0px' ); 
							$('#logo-counter').text(6); break;
		case 'acmilan': 	$('.logo-slide').css("background-position", (6*a)+'px 0px' );
					 		$('.name-slide').css("background-position", (6*b)+'px 0px' ); 
							$('#logo-counter').text(7); break;
	}
	
	
}

$('.arr-p').click(function(){
	var dir = $(this).attr('dirc'); var counter = parseInt($('#logo-counter').text());
	var c = (dir == "+") ? (counter + 1) : (counter - 1);
	if(c == 8){c = 1;}else if(c == 0){c = 7;}
	
	var logol = $('.logo-slide').css('background-position');
	logol = logol.split(' ')
	var lg = (dir == "+") ?  parseInt(logol[0]) - 84 : parseInt(logol[0]) + 84;
	
	if(lg > 0){lg = -504}else if(lg <= - 588){lg = 0}	
	
	$('.logo-slide').css("background-position",  lg + 'px 0px' );
	
	/////
	var namel = $('.name-slide').css('background-position');
	namel = namel.split(' ');
	var lg2 = (dir == "+") ?  parseInt(namel[0]) - 150 : parseInt(namel[0]) + 150;
	
	if(lg2 > 0){lg2 = -900}else if(lg2 <= -1050){lg2 = 0}
	
	$('.name-slide').css("background-position",  lg2 + 'px 0px' );
	

	$('#logo-counter').text(c)

})
	
	//click url
	$('.name-slide,.logo-slide').click(function(){
		c = parseInt($('#logo-counter').text()); 
		switch(c)
		{
			case 1: sendUrl(base_url + 'barca'); break;
			case 2: sendUrl(base_url + 'arsenal'); break;
			case 3: sendUrl(base_url + 'chelsea'); break;
			case 4: sendUrl(base_url + 'liverpool'); break;
			case 5: sendUrl(base_url + 'madrid'); break;
			case 6: sendUrl(base_url + 'manu'); break;
			case 7: sendUrl(base_url + 'acmilan'); break;
		}
	})

	
	//mouseover
	$('.arr-p, .name-slide,.logo-slide').mouseover(
		function(){
			$(this).css('cursor', 'pointer')
	})

//$("a").attr('onMouseOver',"window.status='';return true");
//CONTROLS/SETS DEFAULT VALUES FOR INPUT BOXES
$('input[@type=text]').css('color','#999');
$('input[@type=text]').focus(function(){ if($(this).val() == $(this).attr('defaultValue')) { $(this).val(''); } $(this).css('color','#333'); }); 
$('input[@type=text]').blur(function(){ if($(this).val() == '') { $(this).val($(this).attr('defaultValue')); $(this).css('color','#999'); $(this).css('color','#999')} }); 

//ADD EFFECTS TO THE LEFT TOP MENU
$("div.tmp-btn-glassy").fadeTo("fast", 0.90); 
	//send the myzone click
	$('div.tmp-btn-glassy').mouseover(
		function(){
			$(this).fadeTo(400, 1);
			$(this).css('cursor', 'pointer')
		}).mouseout(
			function(){
			$(this).fadeTo( 400, 0.90);
	});
/*
 * jQuery FixClick Plugin
 * version: 1.0
 * @requires jQuery v1.2.2 or later
 *
 * Copyright (c) 2008 AlloVince
 * Examples at: http://allo.ave7.net/fixclick
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(jQuery)(function($){$.fn.fixClick=function(B,A){var _=this;this.click=B;this.dblclick=A;this.firstClick=false;this.timer=null;this.delay=100;$(this).click(function($){var A=this;this.e=$;_.firstClick==false?_.timer=setTimeout(function(){_.click(A.e);_.firstClick=false},_.delay):"";_.firstClick=true}).dblclick(function($){clearTimeout(_.timer);_.firstClick=false;_.dblclick($)});return this}})(jQuery)
////////////////////////////////////////////
});

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height(); 
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});

	group.height(tallest);
	
}

//set array of the site's bas links
var xURL = {
	
	//Inbox
	base: window.location.host,
	
	};


//set array of the site's links
var xlinks = {
	
	//Inbox
	new_message: xURL.base + "",
	
	};
	
/*======================================================================
Converts the hash values of a url to arrays
======================================================================*/
function xHasher()
{
	var subs;
	var yhash = new Array(yhash);
	var ahash = unescape(window.location.hash.substring(1));
	yhash['sx'] = yhash['mx'] = false;
	if(ahash)
	{
		var ahash = ahash.split('&');
		
		if(isArray(ahash))
		{
			for(subs in ahash)
			{
				xsub = ahash[subs].split('=');
				yhash[xsub[0]] = xsub[1];				
			}
			
			return yhash;
		}
		
	}
	
	return false;
}

/*==================================================================
Verify user login message when we send ajax results
===================================================================*/
function doAjaxLogin(msg)
{
	if(msg == null){return true;}
	if(msg.login){return true;}
}

/*==================================================================
Adds the hash values to a url
===================================================================*/
function hashUrl(str)
{
	window.location.hash = str.toLowerCase();
}

/*==================================================================
Redirect page to a url
===================================================================*/
function sendUrl(str)
{
	window.location = str;
}

/*==================================================================
Search for web urls in string and make it a link
===================================================================*/
function replaceURLWithHTMLLinks(text) {
  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  return text.replace(exp,"<a href='$1'>$1</a>"); 
}

/*==================================================================
Check if the sent variable is an Array
===================================================================*/
function isArray(obj){
	
	if(jQuery.browser.msie == true)
	{
		return(typeof(obj)=="undefined")?false:true;
	}
	else
	{
		return(typeof(obj.length)=="undefined")?false:true;
	}
	
}
/*==================================================================
Modify Boxy Alerts
===================================================================*/
function jboxy(msg, args, err)
{
	var x = (err == 1) ? 'error' : "success";
	Boxy.alert('<div class="'+x+'">'+msg+'</div>', null, args);	
}

/*==================================================================
* Add up different times to get total
* Param: time as an Array of all the times to add up
*===================================================================*/
function sum_times(time)
{
	
	var hr = mn = sc = secs = 0;	
	//loop through the array of times and work on each
	for (var i = 0; i < time.length; i++) 
	{
		len = time[i];
		len = len.split(':');
		 
		//Check if this time is hour or mins
		var f = len.length;
		
		if(f > 2)
		{
			hr = parseInt(len[0]), mn = parseInt(len[1]), sc = parseInt(len[2]);
		}
		else
		{
			hr = 0, mn = parseInt(len[0]), sc = parseInt(len[1]);
		}
		
		//convert the time to seconds
		secs += hr * 3600; secs += mn * 60; secs += sc;	
	}

	//Get the number of hours, mins and secs from the total seconds
	//and convert to string
	hr = Math.floor(secs/3600).toString();
	secs -= hr * 3600;
	mn = Math.floor(secs/60).toString();
	secs -= (mn * 60); secs = secs.toString();
	
	
	//Append 0 to the front of each if length = 1
	if(hr.length == 1){hr = '0'+ hr;}
	if(mn.length == 1){mn = '0'+ mn;}
	if(secs.length == 1){secs = '0'+ secs;}
	
	return totalTime = hr+':'+mn+':'+secs;

}

/*==================================================================
* Return plural of a word
* Param: count, word, s or es
*===================================================================*/
function xInflector(counter, word, opt)
{
	if(counter > 1 || counter == 0)
	{
		s = (opt != null) ? 'es' : 's';
		return ' ' + word + s;
	}
	else
	{
		return ' ' + word;
	}		
}

/*==================================================================
* beautify a decimal number like currency 00.00
* Param: number a decimal point
*===================================================================*/
function nInflector(number,isCurrency)
{
	var x = '';
	x = number.toString(); x = x.split('.');
	if(isCurrency == true){
		x0 = x[0]
	}
	else
	{
		if(x[0].length == 1){ x0 = '0' + x[0];}else{x0 = x[0]}
	}
	if(x[1].length == 1){ x1 = x[1] + '0';}else{x1 = x[1]}
	
	return x0 + '.' + x1;
}

/*==================================================================
* Make first letter capital 
* Param: str
*===================================================================*/
function strCapital(str) { //v2.0
	return str.substring(0,1).toUpperCase() + str.substring(1);
}

/*==================================================================
* Open a window
* Param: url, window name, features
*===================================================================*/
function popWindow(theURL,winName,features, scrollbar) { //v2.0
	var f = {1:'width=720,height=600', 2:'width=500,height=500'};
	var s = {0:'scrollbars=no', 1:'scrollbars=yes'};
  window.open(theURL,winName,f[features],s[scrollbar]);
}
