///////////////////// 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#addStuffContainer');
	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({
        connectWith: '.groupWrapper',
        tolerance: 'pointer',
        update: function() {
            var result1 = $('#columns').sortable('toArray');
            var result2 = $('#column2').sortable('toArray');
            var result3 = $('#column3').sortable('toArray');
            //$.cookie('listOrder', $('#column1').sortable("toArray"), { expires: setCookieExpiry, path: "/" });
            document.getElementById("ctl00_mainarea_txt_sort").value = result1;
            //document.getElementById("ctl00_mainarea_txt_sort2").value = result2;
            //document.getElementById("ctl00_mainarea_txt_sort3").value = result3;
            //callDeleteWidget(document.getElementById("ctl00_mainarea_txt_sort2").value + '/' + 'position2' + '/' + 'maximise');
            //callDeleteWidget(document.getElementById("ctl00_mainarea_txt_sort").value + '/' + 'position' + '/' + 'maximise');

            //callDeleteWidget(document.getElementById("ctl00_mainarea_txt_sort3").value + '/' + 'position3' + '/' + 'maximise');

            alert(result1);
            //alert(result2);
            //alert(result3);
            //alert(document.cookie);
        }

    });

    $(".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') {
        callDeleteWidget(this.id + '/' + 'update' + '/' + 'maximise');
        //alert("maximise");
        targetContent.show();
        $(this).removeClass("collapsed");
    } else {
    callDeleteWidget(this.id + '/' + 'update' + '/' + 'minimise');
    //alert("minimise");
        targetContent.hide();
        $(this).addClass("collapsed");
    }
    return false;
};


$(function() {

    $(".groupItem a.remove").click(function() {
        //alert("helllo");
        //alert(this.id);
        if (confirm('This widget will be removed, ok?'))

               $(this).parents(".groupItem").animate({ opacity: 0 }).slideUp("fast");
           callDeleteWidget(this.id + '/' + 'delete' + '/' + 'maximise');
    });
});

/* /////////////////////////////////////////////////// [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 tabContainers1 = $('div#tabsCntDreamTeams > div');
    tabContainers1.hide().filter(':first').show();
    $('div#tabsDreamTeams ul li a').click(function() {
        tabContainers1.hide();
        tabContainers1.filter(this.hash).show();
        $('div#tabsDreamTeams 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#tabsCntDreamTeams > div');
    tabContainers.hide().filter(':first').show();
    $('div#tabsDreamTeams ul li a').click(function() {
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $('div#tabsDreamTeams ul li a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();
});

$(function() {
    var tabContainers = $('div#tabsCntmvc > div');
    tabContainers.hide().filter(':first').show();
    $('div#tabmvc ul li a').click(function() {
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $('div#tabmvc ul li a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();
});


$(function() {
    var tabContainers = $('div#tabscntMyFanTeams > div');
    tabContainers.hide().filter(':first').show();
    $('div#tabsMyFanTeams ul li a').click(function() {
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $('div#tabsMyFanTeams 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 = "";
	}	
}
