// JavaScript Document
// **********************************************
function Activation(){
	var tmpImgcount=0;
	if(tmpImgcount=$(imgAllJQ).length){
		$(imgAllJQ+":not(.empty)").click(function(){Activation_Img_Container_Modal(this);});
		if(tmpImgcount>imgAllMax){
			var htmlKod='<div class="img_scroll_top"></div><div class="img_scroll_bottom"></div>';
			$(htmlKod).appendTo("#stranka");
			Window_Resize();
			$("#stranka div.img_scroll_top").hide();
			$("#stranka div.img_scroll_bottom").show();
			$("#stranka div.img_scroll_top").click(function(){Scroll_Img("top", tmpImgcount);});
			$("#stranka div.img_scroll_bottom").click(function(){Scroll_Img("bottom", tmpImgcount);});
		}
	}
	if($("#login").length){
		$("#login").submit(function(){
			window.open("ftp://"+$("#user_name").val()+":"+$("#password").val()+"@ftp.coreproduction.cz");
			$("#login").reset();
			return false;
		});
	}
	$(window).resize(Window_Resize);
}
// **********************************************
function Activation_Img_Container_Modal(kdo){
	var tmpID=$(kdo).attr('ID');
	var htmlKod='<div id="modal"><div class="img_modal"><div class="film"></div><div class="close"></div></div></div>';
	$(htmlKod).appendTo("BODY");
	$("#modal div.img_modal div.close, #modal").click(function(){Close_Img_Container();});
	$("#modal div.img_modal").click(function(event){event.stopPropagation();});
	if(!appleMobile){
		htmlKod='<object type="application/x-shockwave-flash" data="/flv/player_flv_maxi.swf" width="849" height="549" style="margin: 20px 20px 0px 20px"><param name="movie" value="/flv/player_flv_maxi.swf"><param name="FlashVars" value="margin=0&amp;bgcolor=000000&amp;bgcolor1=000000&amp;bgcolor2=000000&amp;showstop=1&amp;showvolume=1&amp;showtime=1&amp;showplayer=always&amp;showiconplay=1&amp;iconplaybgcolor=444444&amp;iconplaybgalpha=50&amp;showtitleandstartimage=1&amp;showloading=always&amp;buffershowbg=0&amp;buffermessage=&amp;autoload=1&amp;config=/flv/conf-'+tmpID+'.php"></object>';
		$(htmlKod).appendTo(newModalImgContainerJQ+" div.film");
	}else{
		$("#modal div.img_modal div.film").load("/flv/conf-apple-"+tmpID+".php",function(response, status, xhr){
			if(status == "error"){
				alert("Video\n" + xhr.status + " " + xhr.statusText);
			}else{
				$("#modal div.img_modal div.film video."+tmpID).show();
			}
		});
	}
	if($($(modalPopisekContainerJQ+" div."+tmpID)).length){
		$(modalPopisekContainerJQ+" div."+tmpID).clone().insertAfter("#modal div.img_modal div.film");
	}
	$(newModalImgContainerJQ+", "+newModalImgContainerJQ+" div.film").show(0);
	Window_Resize();
}
// **********************************************
function Scroll_Img(kam, kolik){
	var tmp_rows=Math.ceil(kolik/4);
	if(kam=="top"){
		$(imgContainerJQ+" div.clearimg").css({'top': '-=143px'});
		$(imgContainerJQ).stop(true, true).animate({'top': '+=143px'}, 143, "linear");
		imgRowActual--;
	}else if(kam=="bottom"){
		$(imgContainerJQ+" div.clearimg").css({'top': '+=143px'});
		$(imgContainerJQ).stop(true, true).animate({'top': '-=143px'}, 143, "linear");
		imgRowActual++;
	}else{
		return;
	}
	if((imgRowActual+4)>=tmp_rows){
		$("#stranka div.img_scroll_bottom").hide();
	}else{
		$("#stranka div.img_scroll_bottom").show();
	}
	if(imgRowActual>0){
		$("#stranka div.img_scroll_top").show();
	}else{
		$("#stranka div.img_scroll_top").hide();
	}
}
// **********************************************
function Close_Img_Container(){
	$("#modal").remove();
}
// **********************************************
function Window_Resize(){
	if($("#modal div.img_modal").length){
		$(newModalImgContainerJQ).css({'top' : parseFloat($(obsahJQ).offset().top)+0});
		$(newModalImgContainerJQ).css({'left' : parseFloat($(obsahJQ).offset().left)+0});
	}
	if($(imgAllJQ).length>imgAllMax){
		$("#stranka div.img_scroll_top").css({'top' : parseFloat($(obsahJQ).offset().top)+($(obsahJQ).height()/2)-26, 'left' : parseFloat($(obsahJQ).offset().left)+$(obsahJQ).width()-7});
		$("#stranka div.img_scroll_bottom").css({'top' : parseFloat($(obsahJQ).offset().top)+($(obsahJQ).height()/2)+2, 'left' : parseFloat($(obsahJQ).offset().left)+$(obsahJQ).width()-7});
	}
}
// **********************************************
// **********************************************
function Nove_Okno(kdo) {
	window.open(kdo.href);
	return false;
} 
// **********************************************
// **********************************************
// **********************************************
var obsahJQ="#obsah";
var imgContainerJQ=obsahJQ+' div.img_panel div.img_cont';
var imgAllJQ=imgContainerJQ+' div.img';
var modalPopisekContainerJQ=obsahJQ+' div.popisek_modal';
var modalVideoContainerJQ=obsahJQ+' div.apple_video_modal';
var newModalImgContainerJQ='#modal div.img_modal';
// **********************************************
var imgAllMax=16;
var imgRowActual=0;
var imgRowHeight=143;
// **********************************************
var appleMobile=false;
if(navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/iPad/i)){
 appleMobile=true;
}
// **********************************************
// **********************************************
$(window).ready(Activation);
// **********************************************
// **********************************************
//if (console && console.log){console.log('Stav: ' + stav);}

