
	function assignTooltipsLeft(wn){
		$('#w'+wn+' .box').removeClass('box').addClass('box-tmp');
		$('#w'+wn+' .sub').removeClass('sub').addClass('sub-tmp');
		$('#w'+wn+' a.with-tooltip').cluetip({
			local:true,
			arrows: true,
			cursor: 'pointer',
			cluetipClass: 'jtip arrow-left', 
			hoverIntent: true,
			mouseOutClose: true,
			dropShadow: false,
			showTitle:false,
			topOffset:0,
			leftOffset:12,
			sticky:true,
			closeText: '<img src="assets/i/icons/close.png" alt="close" />',
			cluezIndex:30000,
			activation: 'click'
		});
		$('#w'+wn+' .box-tmp').removeClass('box-tmp').addClass('box');
		$('#w'+wn+' .sub-tmp').removeClass('sub-tmp').addClass('sub');
	}
	function assignTooltipsRight(wn){
		$('#w'+wn+' a.with-tooltip').cluetip({
			local:true,
			arrows: true,
			cursor: 'pointer', 
			cluetipClass: 'jtip arrow-right', 
			hoverIntent: true,
			mouseOutClose: true,
			dropShadow: false,
			showTitle:false,
			positionX:"right",
			topOffset:0,
			leftOffset:-8,
			sticky:true,
			closeText: '<img src="assets/i/icons/close.png" alt="close" />',
			cluezIndex:30000,
			activation: 'click'
		});
	}

	function contentAutoScroll(ele){

		ele.everyTime(15000, "time-"+ele.attr("id"),function() {
			if (ele.find(".tabs li.active").next("li").length){
				obj = ele.find(".tabs li.active").next().children("a")
			}else{
				obj = ele.find(".tabs ul li:first").children("a")
			}
			autoChange(obj)
		});

	}

	function autoChange(obj){

		obj.parents(".widget").children(".box").removeClass('box-active');

		idAt = obj.attr("href");
		idAtl = idAt.lastIndexOf('#');
		idAt = idAt.substring(idAtl);

		idA = obj.parents("ul").children(".active").children("a").attr("href");
		idAl = idA.lastIndexOf('#');
		idA = idA.substring(idAl);

		if (idA != idAt) {

			$(idA).fadeOut("fast", function(){
				//$(this).parent(".entry-wrap").height($(this).height())
				$(this).removeClass('box-active');
			});
			$(idAt).fadeIn("fast", function(){
				$(this).addClass('box-active');
				obj.parents("ul").children("li").removeClass('active');
				obj.parents("li").addClass('active');
				//$(this).parent(".entry-wrap").height("100%");
			});

		}

	}

	$(document).ready(function() {

		$("a[rev='external']").live("click", function(){
			this.target = "_blank";
		});

		$(".bone:not(#admin) .play-button span.pause-action").live("click", function(){
			obj=$(this).parents(".widget").attr("id")
			$("#"+obj).stopTime("time-"+obj)
			$(this).removeClass("pause-action").addClass("play-action")
		});

		$(".bone:not(#admin) .play-button span.play-action").live("click", function(){
			obj=$(this).parents(".widget").attr("id")
			contentAutoScroll($("#"+obj))
			$(this).removeClass("play-action").addClass("pause-action")
		});

		$(document).bind('click', function(event) {
			if(! $(event.target).is('.tabs') && ! $(event.target).parents().is('.tabs') ){
				$(".tabs").removeClass("tabs-active");
			}
			if(! $(event.target).is('#cluetip') && ! $(event.target).parents().is('#cluetip') ){
				$("#cluetip").removeClass("clue-right-jtip").removeClass("cluetip-jtip").css("display","none");
			}
		});

		$('.tabs:not(.tabs-active):not(.empty-tabs) li.active,.tabs:not(.empty-tabs) .arrow,.tabs-active li:first-child').live("click", function(){
			var tmp = $(this).parents(".widget").attr("id");
			$(".widget:not(#"+tmp+") .tabs").removeClass("tabs-active");
			$(this).parents(".tabs").toggleClass("tabs-active");
			return false;
		});

		$('.tabs-active li a').live("click", function(){

			obj=$(this).parents(".widget").attr("id")
			$("#"+obj).stopTime("time-"+obj)
					
			$(this).parents(".widget").children(".entry").children(".entry-wrap").children(".play-button").children().removeClass("pause-action").addClass("play-action")

			if ($(this).attr("href") == '#top-zeroes' || $(this).attr("href") == '#zeitgeist')
				$(this).parents(".widget").children(".entry").children(".entry-wrap").children(".widget-status").hide();
			if ($(this).attr("href") == '#top-heroes' || $(this).attr("href") == '#search-queries')
				$(this).parents(".widget").children(".entry").children(".entry-wrap").children(".widget-status").show();

			autoChange($(this));

			$(this).parents(".tabs").removeClass("tabs-active");

			return false;
		});

		$('.tabs:not(.empty-tabs) li').live("mouseover", function(){
			$(this).addClass("hover");
		}).live("mouseout", function(){
			$(this).removeClass("hover");
		});

		$('.tabs:not(.tabs-active) a,.tabs:not(.tabs-active) span').live("mouseover", function(){
			$(this).parent().addClass("alt-hover");
		}).live("mouseout", function(){
			$(this).parent().removeClass("alt-hover");
		});

		contentAutoScroll($("#w1"));
		contentAutoScroll($("#w2"));
		assignTooltipsLeft(3);
		assignTooltipsLeft(4);
		assignTooltipsLeft(5);
		assignTooltipsLeft(6);
		assignTooltipsRight(7);
		assignTooltipsRight(8);

		$('.more-down').live("click", function(){
			var objT=$(this).parents(".widget");
			objT.addClass("sub-active").find(".sub").slideDown("slow");
			return false;
		});

		$('.more-up').live("click", function(){
			var objT=$(this).parents(".widget");
			objT.find(".sub").slideUp("slow",function(){
				objT.removeClass("sub-active")
			});
			return false;
		});

		$('.view-more-field a').live("click", function(){
			var tmp = $(this).attr("href");
			var tmpl = tmp.lastIndexOf('#');
			tmp = tmp.substring(tmpl);
			$(tmp).addClass("more-field-active");
			return false;
		});

		$('.delete-link').live("click", function(){
			$(this).parents("tr").next("tr.alt-box").remove()
			$(this).parents("tr").remove()
			return false;
		});

	});
