﻿jQuery.noConflict();

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

function pageOpen(pageId,lastPageId,contentHeight) {

	jQuery("#page").hide();
	jQuery("#footer").hide();

	if (pageId == 'uvod' || pageId == 'preloader') {
		// nastaveni vysky flashe podle obsahu flashe, min. 630px 
		if (contentHeight < 630) {
			jQuery("#flashcontent").height(630);
		} else {
			jQuery("#flashcontent").height(contentHeight);
		}
	}

	/* nacitani obsahu do div#page */
	if (pageId == 'uvod') {
		//document.title = 'Úvod | ČEZ Smart Grids';
		pageLoad('/edee/content/pubutf/fmo/smartgrids/cs/smart-grids.html #content', 'Úvod | ČEZ Smart Grids');
	}
	if (pageId == 'smartgrids') {
		pageLoad('/edee/content/pubutf/fmo/smartgrids/cs/smart-grids.html #content', 'Smart Grids | ČEZ Smart Grids');
	}
	if (pageId == 'novinky') {
		pageLoad('/edee/content/pubutf/fmo/smartgrids/cs/novinky/ #content', 'Novinky | ČEZ Smart Grids');
	}
	if (pageId == 'zeptejteSe') {
		pageLoad('/edee/content/pubutf/fmo/smartgrids/cs/zeptejte-se.html #content', 'Zeptejte se | ČEZ Smart Grids');
	}
	if (pageId == 'fotogalerie') {
		pageLoad('/edee/content/pubutf/fmo/smartgrids/cs/fotogalerie.html #content', 'Fotogalerie | ČEZ Smart Grids');
	}
	if (pageId == 'multimedia') {
		pageLoad('/edee/content/pubutf/fmo/smartgrids/cs/multimedia.html #content', 'Multimédia | ČEZ Smart Grids');
	}
	if (pageId == 'vrchlabi') {
		pageLoad('/edee/content/pubutf/fmo/smartgrids/cs/vrchlabi.html #content', 'Smart region Vrchlabí | ČEZ Smart Grids');
	}
	if (pageId == 'projekty') {
		pageLoad('/edee/content/pubutf/fmo/smartgrids/cs/smart-metering.html #content', 'Pilotní projekty | ČEZ Smart Grids');
	}
	if (pageId == 'evropsky') {
		pageLoad('/edee/content/pubutf/fmo/smartgrids/cs/evropsky-kontext.html #content', 'Evropský kontext | ČEZ Smart Grids');
	}
	
	jQuery("#footer").fadeIn("slow");
	
	// console.log(pageId);
	
}

function pageLoad(url, title, obj) {
		
	if (title) {
		document.title = title;
	} 	
	if (url && !jQuery("#getFlash").html()) {
		jQuery("#page").hide();
		jQuery("#preloader").show();
		jQuery("#page").load(url, function(){
		
			var pageHeight = jQuery("#page").height() + 200;
			if (jQuery(".mediaspace").html()) { 
				pageHeight = pageHeight + 240; 
			}
			if (pageHeight < 630) {
				jQuery("#flashcontent").height(630);
			} else {
				jQuery("#flashcontent").height(pageHeight);
			};
			
			jQuery(".pagination").find(".separator-orange").next(".separator-grey").remove(); 
			jQuery(".pagination").find(".separator-orange").prev(".separator-grey").remove();
			jQuery(".pagination").find(".separator-grey").next(".separator-grey").remove(); 
			
			jQuery(".flvPlay").each(function(i){
				var url = jQuery(this).attr("rel");
				jQuery(this).attr("id","player"+i);
				playMedia(url,this,"player"+i);
			});
			
			jQuery("a.fancybox").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
					var caption = jQuery("span.caption", this.orig.context).html(); 
					return '<p id="fancybox-title-over">Obrázek ' +  (currentIndex + 1) + ' / ' + currentArray.length + '&nbsp;&nbsp;&nbsp;' + caption + '</p>';
				}
			});
			
			jQuery("#footer").fadeIn("slow");
			jQuery("#preloader").hide();
			jQuery("#page").fadeIn("slow");
		});
	} else {
		var href = jQuery(obj).attr("href");
		document.location.href = href;
	}

	return false;
}

function playMedia(url,containerEl,embedId) { 
	var flashvars = {
		file: url,
		skin: "/edee/content/sysutf/sm2/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/sm2/swf/JW_player.swf", embedId, "320", "240", "9.0.0","/edee/content/sysutf/sm2/swf/expressInstall.swf", flashvars, params);
}

/* Formular Zeptejte se */
function checkSmgFaq(myform) { 
		var okMsg = 'Děkujeme za Váš dotaz. \nNaši specialisté Vám v nejbližší možné době poskytnou potřebné informace.';
		var errorMsg = '';
		
		var jmeno = myform['jmeno'].value;
		var email = myform['email'].value;
		var dotaz = myform['dotaz'].value;
		var go = myform['go'].value;
		
		if (jmeno == '') {
			if(!errorMsg) { myform['jmeno'].focus(); }
			errorMsg += "<span>- Vyplňte prosím <strong>Vaše jmého a příjmení.</strong></span>";
		}
		var regexpEmail=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
		if (email == '' || !regexpEmail.test(email)) {
			if(!errorMsg) { myform['email'].focus(); }
			if(email == '')  {
				errorMsg += "<span>- Vyplňte prosím <strong>Váš e-mail.</strong></span>";
			} else {
				errorMsg += "<span>- Zadaná e-mailová adresa je ve <strong>špatném tvaru.</strong></span>";
			};
		};
		if(dotaz == '') {
			if(!errorMsg) { myform['dotaz'].focus(); };
			errorMsg+="<span>- Vyplňte prosím <strong>Váš dotaz.</strong></span>";
		};
		if(go == '') {
			if(!errorMsg) { myform['go'].focus(); };
			errorMsg+="<span>- Vyplňte prosím <strong>odpověď na kontrolní otázku.</strong></span>";
		};
	
		if(errorMsg) {
			
			var flashHeight = jQuery("#flashcontent").height() - jQuery(".messageBox").height();
			jQuery("#check_n").hide();
			jQuery("#check").hide().html('<div class="messageBox"><div class="alert">'+errorMsg+'</div></div>').slideDown("slow");
			jQuery("#footer").hide();
			jQuery("#flashcontent").height(flashHeight + jQuery(".messageBox").height());
			jQuery("#footer").fadeIn("slow");
			return false;
		} else {
			// jQuery("input[name=go]").val(1);
			okMsg=okMsg.replace("\\n","\n");
			alert(okMsg);
			return true;
		};
}

/* Formular Newsletter */
function checkSmgNewsletter(myform) { 
		var okMsg = 'Váš e-mail byl úspěšně zaregistrován.';
		var errorMsg = '';
		
		var email = myform['email_newsletter'].value;
		
		var regexpEmail=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
		if (email == '' || !regexpEmail.test(email)) {
			if(!errorMsg) { myform['email_newsletter'].focus(); }
			if(email == '')  {
				errorMsg += "<span>- Vyplňte prosím <strong>Váš e-mail.</strong></span>";
			} else {
				errorMsg += "<span>- Zadaná e-mailová adresa je ve <strong>špatném tvaru.</strong></span>";
			};
		};
	
		if(errorMsg) {
			
			var flashHeight = jQuery("#flashcontent").height() - jQuery(".messageBox").height();
			jQuery("#check").hide();
			jQuery("#check_n").hide().html('<div class="messageBox"><div class="alert">'+errorMsg+'</div></div>').slideDown("slow");
			jQuery("#footer").hide();
			jQuery("#flashcontent").height(flashHeight + jQuery(".messageBox").height());
			jQuery("#footer").fadeIn("slow");
			return false;
		} else {
			okMsg=okMsg.replace("\\n","\n");
			alert(okMsg);
			return true;
		};
}

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

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

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

    $("div.single-page a").live("click", function() {
        var fancyHref = $(this).attr("href");
        jQuery.fancybox({'href' : fancyHref});
        return false;
    });    
	
	$("a.fancybox").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
				var caption = $("span.caption", this.orig.context).html();
				return '<p id="fancybox-title-over">Obrázek ' +  (currentIndex + 1) + ' / ' + currentArray.length + '&nbsp;&nbsp;&nbsp;' + caption + '</p>';
			}
	});

    
	// 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
			}
		);
	});
	
	// nastaveni umistneni div#page 
	var bodyWidth = $("body").width();
	var pageLeft = (bodyWidth - 980)/2;
	$("#page").css("left",pageLeft+"px");
	$(window).bind("resize",function(){
		bodyWidth = $("body").width();
		pageLeft = (bodyWidth - 980)/2;
		$("#page").css("left",pageLeft+"px");
	});

	// Videoplayer 
	$(".flvPlay").each(function(i){
		var url = $(this).attr("rel");
		$(this).attr("id","player"+i);
		playMedia(url,this,"player"+i);
	});
	
	$(".pagination").find(".separator-orange").next(".separator-grey").remove(); 
	$(".pagination").find(".separator-orange").prev(".separator-grey").remove();
	$(".pagination").find(".separator-grey").next(".separator-grey").remove();

	$(".contImgLeft").width($(".contImgLeft").find("img").attr("width"));
	$(".contImgRight").width($(".contImgRight").find("img").attr("width"));

    $('body').addClass("jsonly");
	
	/* collapsible lists ASO */
	$('.collapsible > li > h4, .collapsible > li > h3').live('click', function() { 
		var $el = $(this); 
		if (!$("#getFlash").html()) {
			$("#footer").hide();
		}
		if ($el.next('.jshidden').hasClass("expanded")) {
			$el.next('.jshidden').removeClass('expanded').fadeOut('normal', function() {
				/* footer fix - jenom vo flashi */ 
				if (!$("#getFlash").html()) {
				$("#flashcontent").height($("#page").height() + 200);
				$("#footer").fadeIn();
				}
			});	
		} else {
			jQuery('.jshidden').removeClass('expanded').hide();
			$el.next('.jshidden').addClass('expanded').fadeIn('normal', function() {
				/* footer fix - jenom vo flashi */ 
				if (!$("#getFlash").html()) {
				$("#flashcontent").height($("#page").height() + 200);
				$("#footer").fadeIn();
				}
			});	
		}
	});

    
});

