$(document).ready(function(){

	$('#cfform').validate();
	$('.cycle').cycle();
	var windowhash = window.location.hash.substr(1);
	if (windowhash != '') {
		$('.accordion').accordion({ header: '.accordion-header', autoHeight: false, active: '.acc-head-'+windowhash });
	} else {
		$('.accordion').accordion({ header: '.accordion-header', autoHeight: false });
	}
	$('.gallery_thumbs a').fancybox();
	$('.banner-regionalia').fancybox();
	
	/*$('#gallery-newest-slideshow').cycle({ 
	    pager:  '#gallery-newest-nav' 
	});*/

	$('#search-input').focus(function(){
		if ($(this).val() == 'szukaj' ) { $(this).val(''); }
	});
	$('#search-input').blur(function(){
		if ($(this).val() == '' ) { $(this).val('szukaj'); }
	});
	$('#newsletter-input').focus(function(){
		if ($(this).val() == 'e-mail' ) { $(this).val(''); }
	});
	$('#newsletter-input').blur(function(){
		if ($(this).val() == '' ) { $(this).val('e-mail'); }
	});
	
	$('a[rel="external"]').click(function(){
        window.open(this.href);
        return false;
    });
    
    $('a').click(function(){
    	var hash = $(this).attr('href').substr(0, 1);
    	if (hash == '#') {
    		var anchorName = 'a[name="'+$(this).attr('href').substr(1)+'"]';
    		$(window).scrollTo(anchorName, 1000);
    		return false;
    	}
    });
    
    $('#navigation .has-children').click(function(){
    	$('.nested-nav', this).toggle();
    });
    
    $('#primary-navigation .has-children').hover(function(){
    	$('.nested-nav', this).show();
    }, function(){
    	$('.nested-nav', this).hide();
    });
    
    
    $('#otherlinks a, #made-by a, .breadcrumbs a, .copyright a, .text a[class!="accordion-link"]').hover(function(){ $(this).css('color', '#8fa6bf').stop().animate({ color: '#000' }); }, function(){ $(this).stop().animate({color: '#8fa6bf'}); });
    /*$('.nav_box a, .news-pager-right a, .text h3.accordion-header a, .news-pager-left a[class!="pager-active"], #primary-navigation a').hover(function(){ $(this).css('color', '#424242').stop().animate({ color: '#f5f0f0' }); }, function(){ $(this).stop().animate({color: '#424242'}); }); */
    $('.text h3.accordion-header a').hover(function(){ $(this).css('color', '#424242').stop().animate({ color: '#f5f0f0' }); }, function(){ $(this).stop().animate({color: '#424242'}); });
    
    $('.logoitem a img').css('opacity', 0.5);
    $('.logoitem a').hover(function(){
    	$(this).css('color', '#6e6e6e').stop().animate({ color: '#000' });
   		$('img', this).stop().animate({ opacity: 1 });
   	}, function(){ 
   		$(this).stop().animate({color: '#6e6e6e'});
   		$('img', this).stop().animate({ opacity: 0.5 });
   	});
		
});
