///////////////////// JavaScript for common Show Hide /////////////////////////
function ForShow(id){	
	document.getElementById(id).style.display="block";
}
function ForHide(id){
	document.getElementById(id).style.display="none";
}
//////////////////////////////////////////// for adding more stuff ////////////////////////////////////////////
$(function() {
	$('li#addStuff a#btn-slide').bind('click', toogleAddMoreStuff);
});

var toogleAddMoreStuff = function(e)
{
	var targetContent = $('div#addStuffContainernewnew');
	if (targetContent.css('display') == 'none') {
		targetContent.show();
		$(this).addClass("selected");
	} else {
		targetContent.hide();
		$(this).removeClass("selected");
	}
	return false;
};

//////////////////////////////////////////// for fancy check box  ////////////////////////////////////////////
$(function () {
  
  $("input[type!='submit']").each(function(i) {
	  var label = $(this).parent("label");
	  if ($(this).attr("checked") == true) {
		  $(label).addClass("checked");
	  } else {
		  $(label).removeClass("checked");
	  }
	  
  });
  
  $("input[type!='submit']").click(function() {

	  var label = $(this).parent("label");
	  var labels = $(this).parents("ul").find("label");

	  if ($(this).attr("type") == "radio") {
		  $(labels).each(function(i) {
			  $(this).removeClass("checked");
		  });
	  }

	  if ($(this).attr("checked") == true) {
		  $(label).addClass("checked");
	  } else {
		  $(label).removeClass("checked");
	  }

  });
});
//////////////////////////////////////////// JavaScript For Draggable/Sortables ////////////////////////////////////////////
$(function() {

	$('a.collapse').bind('click', toggleContent);

	$(".groupWrapper").sortable({
		  
		  //revert: true,
		  tolerance: 'pointer',
		  handle: '.itemHeader',
		  connectWith: '.groupWrapper',
		  update : function () { 
      		$("input#test-log").val($('#test-list').sortable('serialize')); 
    	  } 
  
	  });
	
  $(".groupItem").addClass("ui-block")
	  .find(".itemHeader")
		  //.addClass("ui-widget-header ui-corner-all")
		  //.prepend('<span class="ui-icon ui-icon-plusthick"></span>')
		  .end()
	  .find(".itemContent");


  $(".groupWrapper").disableSelection();
});
	
var toggleContent = function(e)
{
	var targetContent = $('div.itemContent', this.parentNode.parentNode.parentNode);
	if (targetContent.css('display') == 'none') {
		targetContent.show();
		$(this).removeClass("collapsed");
	} else {
		targetContent.hide();
		$(this).addClass("collapsed");
	}
	return false;
};



/* /////////////////////////////////////////////////// [FOR ALL TABS] ///////////////////////////////////////////////////
-----------------------------------------------------------------------------------------------------------------------------------------------*/
$(function () {
	var tabContainers = $('div#tabsCntFantasyTeams > div');
	tabContainers.hide().filter(':first').show();
	$('div#tabsFantasyTeams ul li a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div#tabsFantasyTeams ul li a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
});
// 
$(function () {
	var tabContainers = $('div#tabsCntTopCricketers > div');
	tabContainers.hide().filter(':first').show();
	$('div#tabsTopCricketers ul li a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div#tabsTopCricketers ul li a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
});


$(function () {
  var tabContainers = $('div#tabsCntWinners > div');
  tabContainers.hide().filter(':first').show();
  $('div#tabsWinners ul li a').click(function () {
	  tabContainers.hide();
	  tabContainers.filter(this.hash).show();
	  $('div#tabsWinners ul li a').removeClass('selected');
	  $(this).addClass('selected');
	  return false;
  }).filter(':first').click();
});



$(function () {
	var tabContainers = $('div#tabsCntTracklist > div');
	tabContainers.hide().filter(':first').show();
	$('div#tabsTracklist ul li a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div#tabsTracklist ul li a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
});



$(function () {
  var tabContainers = $('div#tabsCntTopLeague > div');
  tabContainers.hide().filter(':first').show();
  $('div#tabsTopLeague ul li a').click(function () {
	  tabContainers.hide();
	  tabContainers.filter(this.hash).show();
	  $('div#tabsTopLeague ul li a').removeClass('selected');
	  $(this).addClass('selected');
	  return false;
  }).filter(':first').click();
});
/* /////////////////////////////////////////////////// [FOR CAROUSEL OR SCROLLABLE] ///////////////////////////////////////////////////
-----------------------------------------------------------------------------------------------------------------------------------------------*/
$(function() {
	// initialize scrollable
	$("div#widget-casualgames div.wcg-inner div.casousel").scrollable({
		size: 3
		// items are auto-scrolled in 2 secnod interval
		//interval: 2000,
		// when last item is encountered go back to first item
		//loop: true,
		// make animation a little slower than the default
		//speed: 600,
		// when seek starts make items little transparent
		//onBeforeSeek: function() {
		  // this.getItems().fadeTo(300, 0.2);
		//},
		// when seek ends resume items to full transparency
		//onSeek: function() {
		   //this.getItems().fadeTo(300, 1);
		//} 
	});
});
$(function() {
	// initialize scrollable
	$("div#widget-prizes div.wp-inner div.casousel").scrollable({
		size: 1
		// items are auto-scrolled in 2 secnod interval
		//interval: 2000,
		// when last item is encountered go back to first item
		//loop: true,
		// make animation a little slower than the default
		//speed: 600,
		// when seek starts make items little transparent
		//onBeforeSeek: function() {
		   //this.getItems().fadeTo(300, 0.2);
		//},
		// when seek ends resume items to full transparency
		//onSeek: function() {
		   //this.getItems().fadeTo(300, 1);
		//} 
	});	
});
/* /////////////////////////////////////////////////// [FOR TYPEWRITER NEWS TICKER] ///////////////////////////////////////////////////
-----------------------------------------------------------------------------------------------------------------------------------------------*/
function createTicker(){
	// put all list elements within #ticker-area into array
	var tickerLIs = $("#ticker-area ul").children();
	tickerItems = new Array();
	tickerLIs.each(function(el) {
		tickerItems.push( jQuery(this).html() );
	});
	i = 0
	rotateTicker();
}

function rotateTicker(){
	if( i == tickerItems.length ){
	  i = 0;
	}
  tickerText = tickerItems[i];
	c = 0;
	typetext();
	setTimeout( "rotateTicker()", 5000 );
	i++;
}

var isInTag = false;
function typetext() {	
	var thisChar = tickerText.substr(c, 1);
	if( thisChar == '<' ){ isInTag = true; }
	if( thisChar == '>' ){ isInTag = false; }
	$('#ticker-area').html("&nbsp;" + tickerText.substr(0, c++));
	if(c < tickerText.length+1)
		if( isInTag ){
			typetext();
		}else{
			setTimeout("typetext()", 28);
		}
	else {
		c = 1;
		tickerText = "";
	}	
}