/**
 * Javascript for index page.
 */

jQuery(function(){
	if (!page_shorturl) {
		$("a.demobox").colorbox({
			opacity: 0.3,
			onComplete: function(){
				var element = $.fn.colorbox.element();
				var anchor = element.attr("href");
				var name = element.children("span").first().html();
				window.location.replace(pagelocation + "#" + anchor);
				document.title = name + " « " + site_index_title;
			},
			onClosed: function(){
				window.location.replace(pagelocation + "#/");
				document.title = site_index_title;
			}
		});
	}
	else {
		$("a.demobox").colorbox({
			opacity: 0.3
		});
	}

	$("a.demobox").tooltip({
		position: "top center",
		delay: 0,
		offset: [-5, 0]
	});

	$("select#agc").change(function(){
		$("select#agt").val("");
	});
	
	$("select#pa").change(function(){
		$("select#rg").val("");
	});
	
	$("form#filtres select").change(function(){
		if ($(this).attr("id") != "o") {
			$("input#search").val("");
		}
		$("form#filtres").submit();
	});

	$("select#n").change(function(){
		$("input#nhidden").val($(this).val());
		$("form#filtres").submit();
	});

	if (!page_shorturl) {
		var pagelocation = window.location.href;
		
		if (pagelocation.indexOf("#") > 0) {
			pagelocation = pagelocation.substring(0, pagelocation.indexOf("#"));
	
			if (window.location.hash) {
				var openhref = window.location.hash.substring(1);
				if (openhref.match(site_index_actorregex)) {
					$.fn.colorbox({
						href: openhref,
						opacity: 0.3,
						onClosed: function(){
							window.location.replace(pagelocation + "#/");
							document.title = site_index_title;
						}
					});
				}
			}
		}
	}
	else {
		var openhref = $("a.demobox").first().attr("href");
		$.fn.colorbox({
			href: openhref,
			opacity: 0.3
		});
	}
});
