﻿$(document).ready(function(){ // DOM Ready

// animace satana na lane
var l=$('#lano');  // lano
var s=$('#satan'); // satan

	l.hide(); // skryje lano
	l.delay(5000).slideDown(500);  // zobrazi lano
	s.delay(7000).animate({top:'+=160px'},1000); // animace satana sjeti dolu	
	s.mouseenter(function(){ $(this).stop().animate({top:'+20px'}, 'slow'); }); // pri najeti mysi na prvek
	s.mouseleave(function(){ $(this).stop().animate({top:'-20px'}, 'slow');	}); // pri odjeti mysi z prveku
// END animace satana na lane

// ### MENU ###
	// po NAJETI kurzoru z menu
	$('ul#menu li a.drop').bind("mouseenter", function (event) {
		event.preventDefault();
		$('ul#menu>li>div').show('fast'); // misto show jde i slideDown
	});
	// po ODJETI kurzoru z menu
	$('ul#menu>li').bind("mouseleave", function (event) {
		event.preventDefault();
		$('ul#menu>li>div').hide('fast'); // misto hide jde i slideUp
	});
// ### MENU ###
		
	//Stin pod :header textem a zakulaceni rohu
	$("h1, h2, h3, h4, h5, h6").textShadow();
	$("#menu, #stred").corner('8px');
	$("#address, .content, .news, .malymenu, .obsah_pocasi").corner('bottom 5px');
	
	// Scroll_Top
	//$('a#scroll_top').click(function(){
	//	$('html').animate({scrollTop:0}, 'slow');
	//});
	
	//FadeTo efekt na IMG z 70-100%
	$(".pocasi, .browser, #scroll_nahoru, #reset_anim, .reset_anim, button#btn_social, div#social_slide").fadeTo("slow", 0.7);
	$(".pocasi, .browser, #scroll_nahoru, #reset_anim, .reset_anim, button#btn_social, div#social_slide").hover(function(){
		$(this).stop().fadeTo("slow", 1); },function(){
		$(this).stop().fadeTo("slow", 0.7);
	});
	
	// Colorbox prepocita velikost IFRAME
	$("#nacteni_obsahu").colorbox({
			iframe:true,
			innerWidth:0,
			innerHeight:0,
			scrolling:false,

		onComplete:function(){
			$.colorbox.resize({
			innerHeight:($('iframe').offset().top + $('iframe').height()),
			innerWidth:($('iframe').offset().left + $('iframe').width())
			});
		}
	});
	
	// Pridava child iframe (aktuality) stranku do parent page
    var ws_width = "610";
    var ws_height = "530"; //680
    var ws_iframe_css_final = "border: 0";
    $("#nacteni_obsahu").html('<iframe src="stranky/aktuality/aktuality.html" allowtransparency="true" frameborder="0" scrolling="no" sandbox="allow-same-origin allow-forms allow-scripts" width="' + ws_width + 'px" height="' + ws_height + 'px" style="' + ws_iframe_css_final + '"></iframe>');
	
	// colorbox resize iframe podle contentu
	// http://dot-net-web-developer-bristol.blogspot.com/2011/02/jquery-colorbox-resizing-iframe-to.html

	// inicializace colorboxu pro otvirani odkazu na hlavni strance v iframu
	$(".externi_url").colorbox({width:"95%", height:"95%", iframe:true});

	
	// Otevre colorbox po nacteni historie_firmyni strany a vnem nacte html s flv
//	$.fn.colorbox({href:'stranky/video/video_cdb_cup_desna_2011.html', width:"800px", height:"550px", iframe:true, open:true});
	//banner
	//$.fn.colorbox({href:'stranky/video/CDB_Banner_975x80px_SWF.swf', innerWidth:975, innerHeight:80, iframe:true, open:true});
	$.fn.colorbox({href:'stranky/cdb_cup_desna_2012/cdb_cup_desna_2012.html', width:"800px", height:"550px", iframe:true, open:true});
		
	//MENU - deklarace promenych
	var sekce = $("a");
	var loading = $("#loading");
	var obsah = $("#nacteni_obsahu");

	//zobrazi "Loading..."
	function showLoading(){
		loading
			.css({visibility:"visible"})
			.css({opacity:"1"})	;
	}
	//schova "Loading..."
	function hideLoading(){
		loading.fadeTo(1000, 0);
		obsah.slideDown("slow");
	};
		//Manage click events - upraveny na live
		sekce.live('click',function(){
			//show the loading bar
			showLoading();
			//nacte sekci s ID nebo samostanou stranku
			switch(this.id){
				case "aktuality":
					obsah.slideUp();
					obsah.load("stranky/sections.html #aktuality", hideLoading);
					break;
				case "historie_firmy":
					obsah.slideUp();
					obsah.load("stranky/sections.html #historie_firmy", hideLoading);
					break;					
				case "obchodni_podminky":
					obsah.slideUp();
					obsah.load("stranky/sections.html #obchodni_podminky", hideLoading);
					break;
				case "videa_2011":
					obsah.slideUp();
					obsah.load("stranky/sections.html #videa_2011", hideLoading);
					break;
				case "videa_2010":
					obsah.slideUp();
					obsah.load("stranky/sections.html #videa_2010", hideLoading);
					break;
				case "foto_2011":
					obsah.slideUp();
					obsah.load("stranky/sections.html #foto_2011", hideLoading);
					break;					
				case "foto_2010":
					obsah.slideUp();
					obsah.load("stranky/sections.html #foto_2010", hideLoading);
					break;
				case "foto_cdb_cup_jestrabice_2010":
					obsah.slideUp();
					obsah.load("stranky/sections.html #foto_cdb_cup_jestrabice_2010", hideLoading);
					break;
				case "foto_cdb_cup_2010":
					obsah.slideUp();
					obsah.load("stranky/sections.html #foto_cdb_cup_2010", hideLoading);
					break;
				case "foto_wdk_2011":
					obsah.slideUp();
					obsah.load("stranky/sections.html #foto_wdk_2011", hideLoading);
					break;
				case "foto_wcc_2009":
					obsah.slideUp();
					obsah.load("stranky/sections.html #foto_wcc_2009", hideLoading);
					break;
				case "foto_vyber":
					obsah.slideUp();
					obsah.load("stranky/sections.html #foto_vyber", hideLoading);
					break;
				case "vase_ulovky_2011":
					obsah.slideUp();
					obsah.load("stranky/sections.html #vase_ulovky_2011", hideLoading);
					break;
				case "vase_ulovky_2010":
					obsah.slideUp();
					obsah.load("stranky/sections.html #vase_ulovky_2010", hideLoading);
					break;
				case "vase_ulovky_foto_vyber":
					obsah.slideUp();
					obsah.load("stranky/sections.html #vase_ulovky_foto_vyber", hideLoading);
					break;					
				case "poradna":
					obsah.slideUp();
					obsah.load("stranky/sections.html #poradna", hideLoading);
					break;
				case "clanky_2011":
					obsah.slideUp();
					obsah.load("stranky/sections.html #clanky_2011", hideLoading);
					break;
				case "clanky_2010":
					obsah.slideUp();
					obsah.load("stranky/sections.html #clanky_2010", hideLoading);
					break;					
				case "clanky_archiv":
					obsah.slideUp();
					obsah.load("stranky/sections.html #clanky_archiv", hideLoading);
					break;						
				case "podminky_clenstvi":
					obsah.slideUp();
					obsah.load("stranky/sections.html #podminky_clenstvi", hideLoading);
					break;		
				case "cdb_cup_desna_2010":
					obsah.slideUp();
					obsah.load("stranky/sections.html #cdb_cup_desna_2010", hideLoading);
					break;
				case "cdb_sraz_desna_2011":
					obsah.slideUp();
					obsah.load("stranky/sections.html #cdb_sraz_desna_2011", hideLoading);
					break;	
				case "cdb_cup_desna_2011":
					obsah.slideUp();
					obsah.load("stranky/sections.html #cdb_cup_desna_2011", hideLoading);
					break;
				case "cdb_cup_desna_2012":
					obsah.slideUp();
					obsah.load("stranky/sections.html #cdb_cup_desna_2012", hideLoading);
					break;			
				case "cdb_cup_desna":
					obsah.slideUp();
					obsah.load("stranky/sections.html #cdb_cup_desna_2010", hideLoading);
					break;				
				case "prodejny":
					obsah.slideUp();
					obsah.load("stranky/sections.html #prodejny", hideLoading);
					break;
					
				default:
					//hide loading bar if there is no selected section
					hideLoading();
					break;
			}
		});

//WORKS http://forum.jquery.com/topic/trigger-from-iframe-to-parent-window
//$(document).bind('myCustomTrigger', function() {
//	 alert('hello');
//});
$(document).bind('foto_vase_2011', function() {
//		alert('klikls '+$(this).attr('id'));
	showLoading();
	obsah.slideUp();
	obsah.load("stranky/sections.html #vase_ulovky_2011", hideLoading);
});

$(document).bind('clanky_wdk', function() {
//		alert('klikls '+$(this).attr('id'));
	showLoading();
	obsah.slideUp();
	obsah.load("stranky/sections.html #clanky_2011", hideLoading);
});

$(document).bind('fotky_wdk', function() {
	showLoading();
	obsah.slideUp();
	obsah.load("stranky/sections.html #foto_wdk_2011", hideLoading);
});

$(document).bind('cdb_sraz_desna_2011', function() {
	showLoading();
	obsah.slideUp();
	obsah.load("stranky/sections.html #cdb_sraz_desna_2011", hideLoading);
});
$(document).bind('cdb_sraz_desna_2012', function() {
	showLoading();
	obsah.slideUp();
	obsah.load("stranky/sections.html #cdb_sraz_desna_2012", hideLoading);
});		
		// Google custom search
		$("img#vyhledat").click(function() {
			$.fn.colorbox({href:'stranky/historie_firmy/vyhledat.html', width:"95%", height:"95%", iframe:true });
			return false;
		});
		
		// jQuery qTip2
/*		
		// desna CDB CUP	
		$('ul.malymenu a[title]').qtip({
				position: {
			 		my: 'left top',//sipka
					at: 'right center',
			 		//target: 'mouse',
					target: $("img#devil"),
			 		viewport: $(window), // Keep it on-screen at all times if possible
			 		adjust: { x: -33,  y: 2 }
				},
			   style: {
				  classes: 'ui-tooltip-red ui-tooltip-rounded ui-tooltip-light ui-tooltip-shadow',
				  tip: { corner: true }
			   }
		})
		
		// dablik rika
		$('img#devil').qtip({
           		content:'Vítejte na webu CDB',
				position: {
			 		my: 'left top',//sipka
					at: 'right center',
			 		//target: 'mouse',
					target: $("img#devil"),
			 		viewport: $(window), // Keep it on-screen at all times if possible
			 		adjust: { x: -33,  y: 2 }
				},
			   style: {
				  classes: 'ui-tooltip-red ui-tooltip-rounded ui-tooltip-light ui-tooltip-shadow',
				  tip: { corner: true }
			   }
		});
*/		
		// Reset animaci - tlacitko
		$('ul.malymenu a[title]').qtip({
           		//content:'jsdchkjvhklxcvlkhylx',
				position: {
			 		my: 'left center',//sipka
					at: 'right center',
			 		viewport: $(window), // Keep it on-screen at all times if possible
				},
			   style: {
				  classes: 'ui-tooltip-red ui-tooltip-rounded ui-tooltip-light ui-tooltip-shadow',
				  tip: { corner: true }
			   }
		});
/*		
		// a title v menu - rika
		$('#menu a[title]').qtip({
           		position: {
			 		my: 'left top',//sipka
					at: 'right center',
			 		//target: 'mouse',
					target: $("img#devil"),
			 		viewport: $(window), // Keep it on-screen at all times if possible
			 		adjust: { x: -33,  y: 2 }
				},
			   style: {
				  classes: 'ui-tooltip-red ui-tooltip-rounded ui-tooltip-light ui-tooltip-shadow',
				  tip: { corner: true }
			   }
		});
*/		
		// On-line poradna tip
		$('a#poradna').qtip({
			content:'Potřebujete poradit, nebo prostě jen pokecat o rybářských zážitcích? Stačí kliknout',
           		position: {
			 		my: 'bottom center',//sipka
					at: 'top center',
			 		viewport: $(window), // Keep it on-screen at all times if possible
				},
			   style: {
				  classes: 'ui-tooltip-red ui-tooltip-rounded ui-tooltip-light ui-tooltip-shadow',
				  tip: { corner: true }
			   }
		});		
		
		// tip na pocasi
		$('div.obsah_pocasi a[title]').qtip({
           		position: {
			 		my: 'right center',
					at: 'center',
			 		//target: 'mouse',
					//target: $("img#devil"),
			 		viewport: $(window), // Keep it on-screen at all times if possible
			 		adjust: { x: -33,  y: 2 }
				},
			   style: {
				  classes: 'ui-tooltip-red ui-tooltip-rounded ui-tooltip-light ui-tooltip-shadow',
				  tip: { corner: true }
			   }
		});
		
		// Browser qtip		
		$('p#prohlizece a[title]').qtip({
           		position: {
			 		my: 'right center',
					at: 'center',
			 		//target: 'mouse',
					//target: $("img#devil"),
			 		viewport: $(window), // Keep it on-screen at all times if possible
			 		adjust: { x: -10, y: -5 }
				},
			   style: {
				  classes: 'ui-tooltip-red ui-tooltip-rounded ui-tooltip-light ui-tooltip-shadow',
				  tip: { corner: true }
			   }
		});
/*				
		// Animace se zacnou prehravat po uplynuti 4000ms = 4s
		$("#shark, #mraky").hide(); 
		setTimeout(function(){ 
            $('#shark').pan({fps: 25, speed: 1, dir: 'right'}),
			$('#mraky').pan({fps: 25, speed: 1, dir: 'left'})
		},4000);	
		$("#canvas, #shark, #mraky").fadeTo(8000, 1);
		
		//
		$('#reset_anim').button({
            icons: {
                primary: "ui-icon-gear"
            }
		});
*/		
		// Button Social Site's Slide on Hover/Click up/down
		//$("div.social_slide").hide();
		//$("button.btn_social").button(); //jQ-UI skin button
		//$("button.btn_social").click(function(){
		//		$("div.social_slide").slideToggle("slow"); // toggle/slideToggle
		//});
		
		$('button#fb').qtip({
			content: {
				// Set the text to an image HTML string with the correct src URL to the loading image you want to use
				text: '<img src="img/loading.gif" alt="Loading..." />',
				ajax: {
				   url: 'stranky/facebook.html' //$(this).attr('rel') // Use the rel attribute of each element for the url to load
				},
				title: {
				   text: 'CDB Facebook', // Give the tooltip a title using each elements text
				   button: true // Close button
				}
			 },
			 position: {
				at: 'left center', // Position the tooltip above the link
				my: 'right center',
				viewport: $(window), // Keep it on-screen at all times if possible
				adjust: { screen: true } // Keep the tooltip on-screen at all times
			 },
			 show: {
				//event: 'click', // otevre se jen po kliknuti
				solo: true // Only show one tooltip at a time
				//modal: true
			 },
			 hide: 'unfocus',
			 style: {
				classes: 'ui-tooltip-red ui-tooltip-rounded ui-tooltip-light ui-tooltip-shadow',
			 }
		});
		

		// Nastaveni animaci pro malymenu v levo
		var fadeDuration = 400; //cas v milisekundach
      
      $('.malymenu ul li a').hover(function() {
        $(this).animate({ paddingLeft: '15px' }, fadeDuration); //30px
        $(this).find('.malymenu ul li a').show().animate({ left: -5 }, fadeDuration); // -5
      }, function() {
        $(this).animate({ paddingLeft: '2px' }, fadeDuration); //15px
        $(this).find('.malymenu ul li a').animate({ left: -20 }, fadeDuration).fadeOut(fadeDuration); //-35         
      });

});

$(window).load(function (){ // po nacteni veskerych grafickych prvku
	// http://stackoverflow.com/questions/754982/how-do-i-fade-a-div-in-with-jquery
	// fix pro IE9
	if ($.browser.msie && /9.0/.test(navigator.userAgent) ) {
		$('ul#menu').hide().fadeIn('slow');
		$('a img#devil').hide().fadeIn('fast');
		$('div#beta').hide().fadeIn('fast');
	}
	else { // provede fadeIn efekty se spozdenim na dane prvky
		$('ul#menu').hide().delay(1000).fadeIn('slow');
		$('a img#devil').hide().delay(3500).fadeIn('fast');
		$('div#beta').hide().delay(5000).fadeIn('fast');
	}
	$(this).delay(10000).snowfall({flakeCount:250});
}); // end load
