//init

// Include javascript libraries
includeLibraries();

// Fix bugs
backgroundCache();

// Update links from popout
updateLinksPopout();

// Replace HTML components
replaceComponents();

// Combobox
initCombobox();

// Scrolling
initScrolling(document);

// Wheel
initWheel(document);

// Photos galleries
initPhotosGalleries();

// Drag modules
initDragModule();

// Tab by URL
initTabs();

// Tab by URL
initAlteranteLists();

// Hour sync
hourWrite();
var intHourRefresh = setInterval("hourWrite()", 15000);

/* Combobox */
$(".ctn-combo .ctn-combovalue").click(function() {
	showHideCombo($(this).parent(),1);
});
$(".ctn-combo").hover(
	function() {
		comboOver(this);
	},
	function () {
		comboOver(this);
		showHideCombo(this,0);
	}
);
$(".ctn-combo .ctn-listvalues a").click(function() {
	selectComboValue(this);
	return false;
});
/* // Combobox */

// Clear athletes search field
$(".fld-searchfield").blur(function() {
	clearField(this,"Buscar pelo nome",0);
});
$(".fld-searchfield").focus(function() {
	clearField(this,"Buscar pelo nome",1);
});

// Link print
$(".itm-print a").click(function() {
	window.print();
	return false;
});

// Expand collapse
$(".lnk-collapse").click(function() {
	expandCollapse(this);
	return false;
});

// Open layer
$(".lnk-showlayer").click(function() {
	showHideLayer(this,2);
	return false;
});

// Over layer
$(".lnk-layerOver").hover(
	function() {
		showHideOver(this,1);
	} ,
	function() {
		showHideOver(this,0);
	}
);

// Close layer
$(".ctn-layer .btn-close,.ctn-layerform .btn-close").click(function() {
	showHideLayer(this,0);
	return false;	
});

// Header change country
$(".grp-countries a:first").click(function() {
	$(this).parent().find("ul").slideToggle(200);
	return false;
});

/* Toolbox */
$(".ctn-toolbox").hover(
	function() {
		toggleToolbox(1);
	},
	function() {
		toggleToolbox(0);
	}
);
$(".ctn-toolbox a").click(function() {
	toggleSubToolbox(this,1);
	return false;
});
$(".ctn-subtoolbox").hover(
	function() {
		toggleSubToolbox(null,2);
	},
	function() {
		if ($(this).attr("class").indexOf("ctn-share") > -1) {
			toggleSubToolbox(this,0);
		}
	}
);
$(".lnk-closetoolbox").click(function() {
	toggleSubToolbox(null,0);
	return false;
});
$(".btn-toolboxcancel").click(function() {
	toggleSubToolbox(null,0);
});
/* // Toolbox */

// Hide elements on clickout
$(document).click(function(e) {
	clickOut(e);
});

// Popout
$(".lnk-popout").click(function() {
	openPopup(window.location.href.replace("#","")+"?popup=true",name,940,600,1);
	return false;
});

// Font resize
$(".lnk-fontresize").click(function() {
	fontResize($(this).attr("href").replace("#",""));
	return false;
});

// Tabs
$(".lst-tabs a").click(function() {
	changeTab(this);
	playPauseGallery(null,0);
	$(".clickout:visible").hide();
	$(".ctn-toolbox a").removeClass("selected");
	if (!$(this).hasClass("anchor"))
		return false;
});

/* Drag modules */
$(".lst-dragmodules").find("input:checkbox").change(function() {
	if ($(this).attr("checked")) {
		toggleModule($("."+$(this).val()),1);
	} else {
		toggleModule($("."+$(this).val()),0);
	}
});
$(".ctn-barvolume a").click(function() {
	return false;
});
$(".lst-dragmodules .chk-replace").hover(
	function() {
		elementOver("over",this,1);
	},
	function() {
		elementOver("over",this, 0);
	}
);
$(".lnk-exposeall").click(function() {
	exposeAllModules();
	return false;
});
$(".lnk-collapsemodule").click(function() {
	toggleModule($(this).parents(".ctn-dragmodule"),2);
	return false;
});
$(".lnk-expandmodule").click(function() {
	toggleModule($(this).parents(".ctn-dragmodule"),3);
	return false;
});
$(".lnk-closemodule").click(function() {
	toggleModule($(this).parents(".ctn-dragmodule"),0);
	return false;
});
$(".lnk-dragmodule").click(function() {
	return false;
});
$(".ctn-dragmodule.highlights li").hover(
	function() {
		elementOver("over",this,1);
	},
	function() {
		elementOver("over",this, 0);
	}
);
$(".ctn-dragmodule.highlights li").click(function() {
	toggleHighlight(this, 1);
	return false;
});
$(".ctn-highlight .lnk-backtolive").click(function() {
	toggleHighlight(this, 0);
	return false;
});
/* // Drag modules */

/* Expand and collapse table */
$(".tab-collapse .expand-collapse").each(function() {
	$(this).find("tr:first").hover(
		function() {
			elementOver("over",this,1);
		},
		function() {
			elementOver("over",this,0);
		}
	);
	
	$(this).find("tr:first").click(function() {
		expandCollapseTable(this);
	});
});
/* // Expand and collapse table */

/* Poll */
	// Vote
	$(".ajax-poll").submit(function() {
		votePoll($(this));
		return false;
	});
/* // Poll */

// Back to full article
$(".lnk-fullarticle").click(function() {
	$("a[rel='noticia']").click();
});

/* Photos gallery */
$(".ctn-scrollingcontent a").click(function() {
	openPhoto($(this));
	playPauseGallery(null,0);
	return false;
});
// Back
$(".ctn-photosgallery .lnk-back:first").click(function() {
	obj = $(this).parents(".ctn-scrollingphoto").parent().find(".ctn-scrollingcontent");
	if (obj.find(".selected").prev().size() <= 0) {
		obj.find("li:last").find("a:first").click();
	} else {
		obj.find(".selected").prev().find("a:first").click();
	}
	playPauseGallery(null,0);
	return false;
});
// Next
$(".ctn-photosgallery .lnk-next:first").click(function() {
	obj = $(this).parents(".ctn-scrollingphoto").parent().find(".ctn-scrollingcontent");
	if (obj.find(".selected").next().size() <= 0) {
		obj.find("li:first").find("a:first").click();
	} else {
		obj.find(".selected").next().find("a:first").click();
	}
	playPauseGallery(null,0);
	return false;
});
// First
$(".ctn-photosgallery .ctn-gallerycontrols .lnk-back:first").click(function() {
	obj = $(this).parents(".ctn-scrollingphoto").parent().find(".ctn-scrollingcontent");
	obj.find("li:first").find("a:first").click();
	playPauseGallery(null,0);
	return false;
});
// Last
$(".ctn-photosgallery .ctn-gallerycontrols .lnk-next:first").click(function() {
	obj = $(this).parents(".ctn-scrollingphoto").parent().find(".ctn-scrollingcontent");
	obj.find("li:last").find("a:first").click();
	playPauseGallery(null,0);
	return false;
});
// Zoom
$(".ctn-photosgallery .lnk-zoomphoto").click(function() {
	playPauseGallery(null,0);
});
$(".ctn-photosgallery .lnk-play").click(function() {
	playPauseGallery($(this).parents(".ctn-scrollingphoto").parent(),1);
	return false;
});
$(".ctn-photosgallery .lnk-pause").click(function() {
	playPauseGallery($(this).parents(".ctn-scrollingphoto").parent(),0);
	return false;
});
/* // Photos gallery */