﻿jQuery.noConflict();

eval("try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}");

function vytisknoutstranku(tisknout)
{
	document.write('<a href="#" id="print" onclick="window.print();return false;">'+tisknout+'</a></a> <span class="hidden"> | </span>'); 
};

/* vyskakovací okno pro soutezni pravidla */
function helpWindow_pravidla_souteze(url, windowName) {
	return !window.open(url, windowName, "width=650,height=560,scrollbars=yes,menubar=no,resizable=yes,left=10,top=100");	
} 

function playMedia(url,containerEl,embedId) { 
	var flashvars = {
		file: url,
		skin: "/edee/content/sysutf/kde/swf/CEZ_JW_player_skin.swf",
		fullscreen: "true",
		javascriptid: "JW",
		autostart: "false",
		controlbar: "over",
		dock: "false",
		plugins: "false"
	};
	var params = {
		menu: "false",
		wmode: "transparent",
		allowfullscreen: "true"
	};
	swfobject.embedSWF("/edee/content/sysutf/kde/swf/JW_player.swf", embedId, "320", "240", "9.0.0","/edee/content/sysutf/kde/swf/expressInstall.swf", flashvars, params);
}

function getPlayerVersion() {
	var playerVersion = swfobject.getFlashPlayerVersion(); 
	var output = playerVersion.major;
	return output;
}

/**
  * Funkce pro fancybox, vrací div s popisem fotografie
  * @author ASO
*/
function fancyboxFormatTitle(title, currentArray, currentIndex, currentOpts) {
	var longdesc = '<div class="longdesc">' + (title && title.length ? title : '' ) + '</div>';
	if (title && title.length) {
		return longdesc;
	} else {
		return false;
	}
}


function changeHL(id) {
	if (id == 4) {
		var nextid = 1;
	} else {
		var nextid =  id + 1;
	}
	jQuery("#hp-left h1 span").fadeOut(300); // skryj vsechny HL
	jQuery("#hp-left h1 span#hl"+ nextid).css("opacity","0").css("display","block").animate({opacity: 1}, 1000); // animate namisto fadeIn kvuli spanu, kteremu fadeIn dava display: inline namisto block 	
	setTimeout("changeHL("+ nextid +")","4000");
}


// prepocitani poctu studentu a appendnuti odkazu pro odebirani
var recount = function() {
	var add_student_virtual_id = 1;
	jQuery('table#student_register span.student_register_no').each(function () {
		jQuery(this).html(add_student_virtual_id++);
	});
	jQuery('table#student_register tr#remove_student').remove();
	jQuery('table#student_register').append('<tr id="remove_student"><td>&nbsp;<\/td><td><a class="removeStudent" href="#">Odebrat studenta<\/a><\/td><\/tr>');
}
	
// vsechna jmena do jednoho inputu
var names_to_input = function() {
	var students_name = '';
	jQuery('input.student_name').each(function() {
		students_name += ', ' + jQuery(this).val();
	});
	var students_name = students_name.substring(2);
	jQuery('input#matfyz_idzaci').val(students_name);
}


/***********************************************************/

jQuery(document).ready( // jQuery no conflict block
	function($) {

	/* sumbit miniform using ajax */		
	$("#error404noticeForm").submit( function() {
		actionUrl=$(this).attr("action");
		error404urlValue=$("input[name=error404url]",this).val();
		error404urlreferrerValue=$("input[name=error404urlreferrer]",this).val();
		error404langValue=$("input[name=error404lang]",this).val();
		thanksMsg=$("input[name=error404thanks]",this).val();

		$.get(actionUrl,
			{ go: "1", error404url: error404urlValue, error404lang: error404langValue, error404urlreferrer: error404urlreferrerValue },
			function(data){
				alert(thanksMsg);
				$("#error404noticeForm").hide(); // hide form to prevent multiple submits
			}
		);
	});
	
	/* Videoplayer */
	$(".flvPlay").each(function(i){
		var url = $(this).attr("rel");
		$(this).attr("id","player"+i);
		playMedia(url,this,"player"+i);
	});
	
	/* Rotace HL na HP */
	var randomId = Math.floor(Math.random()*4);
	changeHL(randomId);

	/* Stranka Vyhody prace v CEZ */
	$(".vyhody-detail").hide();
	$(".vyhody-more").click(function () {
		var id = $(this).find("a").attr("href");
		$(".vyhody-detail:not(#id"+id+")").hide();
		$("#id"+id).slideToggle("slow");
		return false;
	});
	$("img.play").css("cursor","pointer");
	$("img.play").click(function () {
		var id = $(this).parent().parent().find(".vyhody-more a").attr("href");
		$(".vyhody-detail:not(#id"+id+")").hide();
		$("#id"+id).slideToggle("slow");
		return false;
	});
	
	/* Skryvani a odkryvani textu s odkazem 'vice' */
	$(".text-detail").hide();
	$(".text-more").click(function () {
		var id = $(this).find("a").attr("href");
		$(".text-more").show();
		$(this).hide();
		$(".text-detail:not(#id"+id+")").hide();
		$("#id"+id).slideToggle("slow");
		return false;
	});
	
	/* Box Dalsi obory */
	$("#dalsi").click(function() {
		$(this).hide();
		$(".toggle").slideDown("slow");
		return false;
	});
	
	/* Box Pozice v oboru */
	$("#vsechny").click(function() {
		$(".box-pozice .box-in:last").addClass("noBorder");
		$(this).hide();
		$(".box-pozice .hidden").slideDown("slow");
		return false;
	});
	$(".box-pozice .box-in").not(":last").mouseover(function() {
		$(this).css("background","#F46D2B url(/edee/content/sys/kde/img/boxgrey_bg_hover.gif) repeat-x left bottom");
		$(this).find("h5").css("color","#fff");
	});
	$(".box-pozice .box-in").not(":last").mouseout(function() {
		$(this).css("background","#FAFAFA url(/edee/content/sys/kde/img/boxgrey_bg.gif) repeat-x left bottom");
		$(this).find("h5").css("color","#F24F00");
	});
	$(".box-pozice .box-in").not(":last").click(function() {
		var url = $(this).find("a").attr("href");
		window.location.href = url;
		return false;
	});
	
	// Nastaveni sirky podle img
	$(".contImgLeft").width($(".contImgLeft").find("img").attr("width"));
	$(".contImgLeft p.description").width($(".contImgLeft").find("img").attr("width")-20);
	$(".contImgRight").width($(".contImgRight").find("img").attr("width"));
	$(".contImgRight p.description").width($(".contImgRight").find("img").attr("width")-20);
	
	// Fancybox
	$("a.fancybox").attr("rel","gallery").fancybox({
		'hideOnContentClick': 'true',
		'titlePosition': 'inside',
		'titleFormat': fancyboxFormatTitle
	});

});
