﻿$(function() {
	// We have JS ----------------------------
	$('body').removeClass('no-js').addClass('js');

	// Cufon
	Cufon.replace('.blocks .nav a', { fontFamily: 'DINPro-Bold' });


	// Open external links in new window ----------------------------
	$('a[rel*=external]').click(function() {
		window.open(this.href);
		return false;
	});


	// Area hovers
	$('#nav area').hover( function () {
		$('#nav a').removeClass('hover').eq( $(this).index( ) ).addClass('hover');
	}, function(){
		$('#nav a').eq( $(this).index( ) ).removeClass('hover');
	}).click(function(){
		window.location = $($(this).attr('href')).attr('href');
		return false;
	});

	$('#blocks area').hover( function () {
		$('#blocks a').removeClass('hover');
		$($(this).attr('href')).addClass('hover');
		if ($($(this).attr('href')).hasClass('visible')) Cufon.refresh();
	}, function(){
		$($(this).attr('href')).removeClass('hover');
		if ($($(this).attr('href')).hasClass('visible')) Cufon.refresh();
	}).click(function(){
		window.location = $($(this).attr('href')).attr('href');
		return false;
	});



	// BOK BLOCZKI
	$('#side-blocks area').hover( function () {
		$('#side-blocks a').removeClass('hover');
		$($(this).attr('href')).addClass('hover');
		if ($($(this).attr('href')).hasClass('visible')) Cufon.refresh();
	}, function(){
		$($(this).attr('href')).removeClass('hover');
		if ($($(this).attr('href')).hasClass('visible')) Cufon.refresh();
	}).click(function(){
		window.location = $($(this).attr('href')).attr('href');
		return false;
	});
	
	$('#slideshow').cycle({ 
	    fx:     	'fade', 
	    speed:  	300, 
	    next:   	'#slideshow', 
	    timeout: 	3000,
	    pause:		1 
	});

	$("a.galleryPhoto").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
//	jQuery.jQueryRandom = 0;
//	jQuery.extend(jQuery.expr[":"], {
//	    random: function(a, i, m, r) {
//	        if (i == 0) {
//	            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
//	        };
//	        return i == jQuery.jQueryRandom;
//	    }
//	});
    
    randomHover = function() {
    	var elems = $('.blink');
    	var rand = Math.floor(Math.random() * elems.length);
    	elems.eq(rand).addClass("hover").delay(1000).queue(function(hover1){
    		$(this).removeClass("hover").delay(1000);
    		jQuery.dequeue(this);
		}).delay(500).queue(function(hover1){
			jQuery.dequeue(this);
			randomHover();
		});
//    	$(".blink:random").addClass("hover").delay(2000).queue(function(hover1){
//    		$(this).removeClass("hover").delay(2000);
//    		jQuery.dequeue(this);
//		}).delay(2000).queue(function(hover1){
//			jQuery.dequeue(this);
//			$(".blink:random").randomHover();
//		});
    };
    randomHover();
    
	$('#slides').slides({
		preload: true,
		preloadImage: 'img/loading.gif',
		play: 5000,
		pause: 5500,
		hoverPause: true,
		generatePagination: false,
		animationStart: function(current){
			$('.caption').animate({
				bottom:-35
			},100);
			if (window.console && console.log) {
				// example return of current slide number
				console.log('animationStart on slide: ', current);
			};
		},
		animationComplete: function(current){
			$('.caption').animate({
				bottom:0
			},200);
			if (window.console && console.log) {
				// example return of current slide number
				console.log('animationComplete on slide: ', current);
			};
		},
		slidesLoaded: function() {
			$('.caption').animate({
				bottom:0
			},200);
		}
	});
	
    swfobject.embedSWF("flash/map.swf",
            "flash", "680", "446", "9.0.0",
            "flash/expressInstall.swf", {}, { wmode: 'transparent' }, {});
});
