﻿$(document).ready(function(){

	$("a[rel^='photo']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		opacity: 0.80, /* Value between 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		default_width: 400,
		default_height: 200,
		counter_separator_label: ' ze ', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded'
	});

	
	$('#goodsSlider-slider ul').jcarousel({
		scroll: 2
	});
	
	$('.jcarousel-skin-tango').jcarousel({
        scroll: 2
    });
	
	$('#goodsSlider-slider a').click(function() {
	
		showImg = '.' + $(this).attr('rel')
				
		$('#goodsSlider-content li').css('display', 'none')
		$(showImg).css('display', 'block')
	
	});
	
	/**************************
		ČLÁNEK - MEDIA
		obsahuje-li článek flashe nebo video, tímto jej aktivujem
	*/
	$('a.media-flashvideo').media();
	
	
	/**************************
		SEARCH - PO KLIKNUTI ODSTRANI TEXT
	*/
	var actualLanguage = $("meta[http-equiv='Content-Language']").attr('content').toLowerCase();
	if (actualLanguage == 'cs-cz') {
		searchtext = 'zadejte hledaný výraz'}
	else if (actualLanguage == 'de-at') {
		searchtext = 'Suchbegriff eingeben'}
	else {
		searchtext = 'Type in the searched word'}
	


	$('#searchText').click(function() {			
		if ($(this).attr('value') == searchtext) {
			$(this).attr("value", "")
		}
	}).blur(function(){
		if ($(this).attr('value') == '') {
			$(this).attr("value", searchtext)
		}
	});
		
	
	/**************************
		SHOW CONTACT
		ZOBRAZI KONTAKTNI FORMULAR
	*/
	$('.showContactForm').click(function() {
	
		$('#lightBoxOverlay').css('height', $(document).height())
		$('#lightBoxOverlay').css('display', 'block')
		
		$('#lightBoxContent').css('width', 510)
		leftPos = ($(document).width() / 2) - ($('#lightBoxContent').width() / 2)
		$('#lightBoxContent').css('left', leftPos)
		$('#lightBoxContent').css('top', $(window).scrollTop() + 50)
		
		$('#lightBoxContent').html('<div id="in_lightBoxContent"><div id="lightBoxContentHeader">Napište nám <a href="javascript:void(0)" class="lightbox-close">zavřít</a></div><div id="lightBoxContentForm" class="clearfix"></div></div>')
		
		
		$('.lightbox-close').click(function() {
			$('#lightBoxOverlay').css('display', 'none')
			$('#lightBoxContent').html('')
			$('#lightBoxContent').css('display', 'none')
		});
		
		
		$.post(
			"/contact-ajax",
			{},
			function(data){
				
				$("#lightBoxContentForm").html(data);
				$('#lightBoxContent').css('display', 'block')
				
			}
		);
				
		return false;
	
	});
	
	/***********
		záložky vyhledávání
	*/
	if($('#contenttab')) {
		$('#contenttab [id^=content-tab-]').each(function(){
			if(!$(this).hasClass('act')) {
				$(this).css('display', 'none')
			}
		});
		SearchAjaxPagination();
	}
	
	$('#searchtabs ul li a').click(function(){
		
		$('[id^=content-tab-]').css('display', 'none')
		$('#searchtabs ul li a').removeClass('act')
		$('#content-'+this.id).css('display', 'block')
		$(this).addClass('act');
		
		return false;
	});
	
	$('input:file').si_files({
		button: {
			src: '../img/file-bg.gif',
			width: 157,
			height: 22
		}
	});	

});

function SearchAjaxPagination() {
	$('.searchajax').click(function(){
		thisHref = $(this).attr('href') + '&layout=ajax'
		parentDiv = $(this).parent().parent().parent().get(0)
		$.post(
			thisHref,
			{},
			function(data){				
				$(parentDiv).html(data);
				SearchAjaxPagination();
			}
		);
		return false;
	});
}

/**************************
	SEND AJAX FORM
	AJAXEM ODESLANI KONTAKTNIHO FORMULARE
*/
function sendContactForm(sender, args) {

	// ziskani nadrazeneho formulare
    var form1 = $(sender).parents('form:first').get(0);
	
	$.post(
		"/contact-ajax",
		$(form1).find(":input").serializeArray(),
		function(data){
			$("#lightBoxContentForm").html(data);
		}
	);
	
	return false;
	
}


/**************************
	ZAVIRANI MAPY
*/
function closeMapIframe() {
	$('#lightBoxOverlay').removeAttr('style')
	$('#lightBoxMapMapIframe').removeAttr('style')
	$('#lightBoxMapMapIframe').html('')
	
	if (location.hash.substring(0,11) == "#directLink") {
		location.href = location.href.substring(0, location.href.indexOf("#directLink"))
	}
};


$(document).ready(function() {
	/**************************
		SHOW MAP
		ZOBRAZI DIV VE KTERE BUDE IFRAME S MAPOU
	*/
	$('.showMap').click(function() {
		
		$('#lightBoxOverlay').css('height', $(document).height())
		$('#lightBoxOverlay').css('display', 'block')
				
		windowWidth = $(window).width() - 40
		windowHeight = $(window).height() - 40		
		$(window).scrollTop(0)
		
		/*
		mode – nastavení záložek
			nezadano 	–> Celá mapa
			route 		–> Volba trasy
			layers 		–> Zobrazení zájmových bodů 
		mapObject – výběr zájmového bodu
			hodnota je z databáze složená tímto způsobem [tblGoods].[nGoodsID] * 1000 + [tblGoodsToDepartment].[nDepartmentID]
		*/
		
		//nefunguje v IE7 a níž
		//var language = $("meta[http-equiv='Content-Language']").attr('content')
		var language = $("html").attr('lang')

		if (this.rel.indexOf("trasa") != -1) {
			href = '/mapa/?language='+language+'&cycleroute='+this.rel.replace("trasa", "")
		} else if (this.rel.indexOf("tipnavylet") != -1) {
			href = '/mapa/?language='+language+'&routeTip='+this.rel.replace("tipnavylet", "")
		} else {
			href = '/mapa/?language='+language+'&mode=&mapObject='+this.rel.replace("objekt", "")
		}
		
		$('#lightBoxMapMapIframe').html('<iframe src="'+href+'" width="' + windowWidth + '" height="' + windowHeight + '" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" />')
		
		
		//$('#lightBoxMapMapIframe').html('<iframe src="mapa/mapa.html" width="' + windowWidth + '" height="' + windowHeight + '" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" />')				
		$('#lightBoxMapMapIframe').css('left', '20px')
		$('#lightBoxMapMapIframe').css('top', '20px')
		$('#lightBoxMapMapIframe').css('display', 'block')
				
		return false;
	
	});
	
	if (location.hash.substring(0,11) == "#directLink") {

		$('#lightBoxOverlay').css('height', $(document).height())
		$('#lightBoxOverlay').css('display', 'block')
				
		windowWidth = $(window).width() - 40
		windowHeight = $(window).height() - 40		
		$(window).scrollTop(0)
		
		/*
		mode – nastavení záložek
			nezadano 	–> Celá mapa
			route 		–> Volba trasy
			layers 		–> Zobrazení zájmových bodů 
		mapObject – výběr zájmového bodu
			hodnota je z databáze složená tímto způsobem [tblGoods].[nGoodsID] * 1000 + [tblGoodsToDepartment].[nDepartmentID]
		*/
		
		$('#lightBoxMapMapIframe').html('<iframe src="/mapa/?readHash=1" width="' + windowWidth + '" height="' + windowHeight + '" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" />')				
		//$('#lightBoxMapMapIframe').html('<iframe src="mapa/mapa.html" width="' + windowWidth + '" height="' + windowHeight + '" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" />')				
		$('#lightBoxMapMapIframe').css('left', '20px')
		$('#lightBoxMapMapIframe').css('top', '20px')
		$('#lightBoxMapMapIframe').css('display', 'block')
	}
});

$(window).resize(function(){
	if($('#lightBoxMapMapIframe').css('display')=='block') {
		windowWidth = $(window).width() - 40
		windowHeight = $(window).height() - 40		
		$('#lightBoxMapMapIframe').find('iframe').attr('width',windowWidth).attr('height',windowHeight)
	}
})

/**************************
	ZOBRAZOVANI PRILOZENEHO SOUBORU VE FORMULARI
*/
function attachfile(input){
	$("#file-url").attr('value', input.value);
	$(".attach-file").show();

}


