$().ready(function() {
	$('#coda-slider-1').codaSlider({
		firstPanelToLoad: 1,
		autoSlide: false,
		autoSlideStopWhenClicked: true,
		dynamicTabs: false
	});
	
	function vypis_obsah(co) {
		$('#ref_content').load('/ajax/listing.php?lang='+ JAZYK +'&ref='+co, function() {
			$('img.ref-img').captify({
				opacity: '0.8',
				hideDelay: 50,	
			});
		});
		$('#ref_content').fadeIn();
	}
	
	var hash = window.location.hash.substr(1);
	var href = $('#ref_nav li a').each(function() {
		var href = $(this).attr('href');
		if(hash==href.substr(1)) {
			$('#ref_nav li#'+href).addClass('current');
			vypis_obsah(hash);
		}

		if((hash==L_INTERNETOVE_OBCHODY || hash==L_INZERTNE_PORTALY || hash==L_KATALOGY || hash==L_INE_PORTALOVE_RIESENIA) && href.substr(1)==L_PORTALOVE_RIESENIA) {
			$('#ref_nav li#'+L_PORTALOVE_RIESENIA).addClass('current');
		}
		
		/*if (href.substr(1)!=L_PORTALOVE_RIESENIA) {
			$('.ref-nav-sub li').each(function() {
				//$('.ref-nav-sub li').removeClass('current');
			}
		}*/
	});
	
	if(hash==L_PORTALOVE_RIESENIA || hash==L_INTERNETOVE_OBCHODY || hash==L_INZERTNE_PORTALY || hash==L_KATALOGY || hash==L_INE_PORTALOVE_RIESENIA) {
		$('#ref_nav_sub_priesenia').slideDown();
	}
	else {
		$('#ref_nav_sub_priesenia').slideUp();
	}
	
	var subhref = $('.ref-nav-sub li a').each(function() {
		var subhref = $(this).attr('href');
		if(hash==subhref.substr(1)) {
			$('.ref-nav-sub li#'+subhref).addClass('current');
			
			vypis_obsah(hash);
		}
	});
	
	$('#ref_nav li a').click(function() {
		var href = $(this).attr('href');
		href = href.substr(1);
		
		var current = $(this).closest('ul').find('li.current');
		current.removeClass('current');

		$('#ref_nav li#'+href).addClass('current');
		vypis_obsah(href);
		
		$('.ref-nav-sub li').each(function() {
			$(this).removeClass('current');
		});
		
		if(href==L_PORTALOVE_RIESENIA) {
			$('#ref_nav_sub_priesenia').slideDown();
		}
		else {
			$('#ref_nav_sub_priesenia').slideUp();
		}
		
		if(href==L_INE_SLUZBY) {
			$('#ref_nav_sub_inesluzby').slideDown();
		}
		else {
			$('#ref_nav_sub_inesluzby').slideUp();
		}
	});
	$('.ref-nav-sub li a').click(function() {
		var href = $(this).attr('href');
		href = href.substr(1);
		
		var current = $(this).closest('ul').find('li.current');
		current.removeClass('current');

		$('.ref-nav-sub li#'+href).addClass('current');
		vypis_obsah(href);
	});
	
	$('#quotes').show();
	$('#quotes').innerfade({
		animationtype: 'fade',
		speed: 750,
		timeout: 10000,
		type: 'random',
		containerheight: '110px'
	});
	
	$("#menu a, #header_jazyky li a, .panel-wrapper-ref a, #ref_content a").live('mouseover', function() {
		$("#menu a, #header_jazyky li a, .panel-wrapper-ref a, #ref_content a").hover(function() {
			$(this).stop().animate({color : "#1e1e1e"},200);
		},function() {
			$(this).stop().animate({color : "#5b5b5b"},200);
		});
	});
	
	$(".spolupachatel").hover(function() {
		$(this).stop().animate({opacity: 1},200);
	},function() {
		$(this).stop().animate({opacity: 0.3},200);
	});
	
	$('a[class=external]').attr('target','_blank');
	
	$("#reflist a").hover(function() {
		$(this).stop().animate({opacity: 1},200);
	},function() {
		$(this).stop().animate({opacity: 0.7},200);
	});
	
	$("#referencia a, #planovac p.down a, .sluzby a").live('mouseover', function() {
		$("#referencia a, #planovac p.down a, .sluzby a").hover(function() {
			$(this).stop().animate({color : "#1e1e1e"},200);
		},function() {
			$(this).stop().animate({color : "#708400"},200);
		});
	});
	
	$('.tooltip').tipsy({gravity: 'sw'});
	$('#header_jazyky a').tipsy({gravity: 'nw'});
	
	$('#odoslat').click(function () { 
		var meno = $('input[name=meno]');  
        var email = $('input[name=email]');  
        var tel = $('input[name=tel]');  
        var sprava = $('textarea[name=sprava]');
           
        var data = 'lang=' + JAZYK + '&meno=' + meno.val() + '&email=' + email.val() + '&tel='  
        + tel.val() + '&sprava='  + encodeURIComponent(sprava.val());   
          
        $.ajax({   
            url: "/ajax/send.php",   
            type: "GET",          
            data: data,       
            cache: false,  
            success: function (html) {                
                if (html=='odoslane') {                    
                    $('#footer_form').fadeOut('slow');                   
                    $('#footer_form_messages').text(L_FORM_ODOSLANY);
                	$('#footer_form_messages').slideDown();  
                } else {
                	$('#footer_form_messages').html(html);
                	$('#footer_form_messages').slideDown();
                	
                }                 
            }         
        });  
        return false;  
    });
    
    $('img.ref-img').captify({
		opacity: '0.8',
		hideDelay: 50,	
	});
});
