/*-------------------------Tools-----------------------------------*/

	$(function(){
		// Accordion
		$("#accordion").accordion({ header: "h3" });
		//hover states on the static widgets
		$('#dialog_link, ul#icons li').hover(
			function() { $(this).addClass('ui-state-hover'); }, 
			function() { $(this).removeClass('ui-state-hover'); }
		);
		// initialize scrollable
		$(".scrollable").scrollable();
	});
	
	$(function() {
		$('.media_images a').lightBox();
		$('.scroll-content-item a').lightBox();
		$('.album-content-photos div a').lightBox();
		$('a[rel~="lightbox"]').lightBox();
	});
	
	function seasonSelect(season, pid, pos){
		$('#playerStatsBySeason').html('<img src="/images/loading.gif" width="32" height="32" alt="..." />');
		$.post("/flash/playerstats.php", {s: ""+season, pd: pid, ps: pos}, function(data) {
			$('#playerStatsBySeason').html(data);
		});
	}
	
	function archiveSeason(){
		var se = $('#aSeason').attr('value');
		var to = $('#aTournament').attr('value');
		var st = $('#aStage').attr('value');
		$('#matchesArchive').html('<img src="/images/loading.gif" width="32" height="32" alt="..." />');
		$.post("/flash/matchesarchive.php", {ssn:se, trn:to, stg:st}, function(data) {
			$('#matchesArchive').html(data);
		});
	}
	
//	$('a#loginlink').click(function() {
//		$('#loginbox').slideToggle(400);
//		return false;
//	});
//	
//	$('a#signuplink').click(function() {
//		$('#signupbox').slideToggle(400);
//		return false;
//	});


/*---------------------------END Tools----------------------------*/
function hide(spanObj){
	var displayStyle = document.getElementById('makeMeScrollable').style.display;
	var value;
	if(displayStyle == 'none'){
		document.getElementById('makeMeScrollable').style.display="block";
		$(spanObj).css('background', 'url(images/images/roll_down.png)');
	}else{
		document.getElementById('makeMeScrollable').style.display="none";
		$(spanObj).css('background', 'url(images/images/roll_up.png)');
	}
	setCookie('showPlaylist', displayStyle == 'none' ? '1' : '0', {expires: 31536000000, path: '/'})
}

function redrawPlaylist(){
	var hidePlaylist = getCookie('showPlaylist') == '0' ? true : false;
	$("div#makeMeScrollable").smoothDivScroll({hiddenOnStart:hidePlaylist});
	if (hidePlaylist) $('#rollPlaylistBtn').css('background', 'url(images/images/roll_up.png)');
}

function getCookie(name) {
	var matches = document.cookie.match(new RegExp(
	  "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
	))
	return matches ? decodeURIComponent(matches[1]) : undefined 
}

function setCookie(name, value, props) {
	props = props || {}
	var exp = props.expires
	if (typeof exp == "number" && exp) {
		var d = new Date()
		d.setTime(d.getTime() + exp*1000)
		exp = props.expires = d
	}
	if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }

	value = encodeURIComponent(value)
	var updatedCookie = name + "=" + value
	for(var propName in props){
		updatedCookie += "; " + propName
		var propValue = props[propName]
		if(propValue !== true){ updatedCookie += "=" + propValue }
	}
	document.cookie = updatedCookie

}

function deleteCookie(name) {
	setCookie(name, null, { expires: -1 })
}

function removePlaylist(obj, video){
	$.post('/ajax/removeplaylist/'+video, function(data){
		if (data){
			delete playlist[video];
			var toDel = obj.parentNode.parentNode;
			var container = toDel.parentNode;
			container.removeChild(toDel);
			document.getElementById('playlistInfo').innerHTML = '';
			//if (video == document.getElementById('video').value) document.getElementById('addPlaylistBtn').style.visibility = 'visible';
			if (container.childNodes.length){
				if (container.childNodes[0].className.indexOf('first_item') == -1) container.childNodes[0].className = 'first_item';
			}
			$("div#makeMeScrollable").smoothDivScroll("recalculateScrollableArea");
			//redrawPlaylist();
		}
	});
}

function showPlaylistInfo(id){
	var obj = document.getElementById('playlistInfo');
	obj.innerHTML = id ? playlist[id] : '';
}


