var scr=0;
var link = new Array(	"/work", 
						"/inspiracje", 
						"/jak-to-robimy", 
						"/jak-to-robimy", 
						"/jak-zabezpieczamy", 
						"/proces-projektowania", 
						"/analiza-procesowa", 
						"/analiza-wymagan"
						);
var time=0;
var int1,int2,int3,int4,int5,int6,int7,int8,int9;
$(document).ready(function()
{
	
	if (window.location.pathname==='/')$('a.main').css('background-position','0px 21px');
	if (window.location.pathname==='/o-nas')$('a.about').css('background-position','-151px 21px');
	if (window.location.pathname==='/portfolio')$('a.projects').css('background-position','-219px 21px');
	if (window.location.pathname==='/work')$('a.rules').css('background-position','-312px 21px');
	if (window.location.pathname==='/akcje')$('a.actions').css('background-position','-427px 21px');
	if (window.location.pathname==='/media')$('a.media').css('background-position','-587px 21px');
	if (window.location.pathname==='/partnerzy')$('a.partners').css('background-position','-654px 21px');
	if (window.location.pathname==='/kontakt')$('a.contact').css('background-position','-744px 21px');

	$(".scroll").scrollable({ circular: true, mousewheel: true }).click(function() {
		//$("#scrolling_main").html("<img src='' />");
	});	
	
	$(".scroll .pics div").click(function(){
		$("#scrolling_main").animate({
			width: '750px',
			height: '600px',
			opacity: 'toggle'
			},1000,
			function(){
				$("#scrolling_main_esc").show();
			}
		);
		$("#scrolling_main").css('background-image',$(this).css('background-image'));
	});
	
	$("#scrolling_main_esc").click(function(){
		$(this).hide();
		$("#scrolling_main").animate({
			width: '0px',
			height: '0px',
			opacity: 'toggle'
			},1000
		);
	});
	
	int1 = window.setInterval("inspiracje(1)",15500);
	int2 = setInterval("inspiracje(2)",10500);
	int3 = setInterval("inspiracje(3)",10500);
	int4 = setInterval("inspiracje(4)",10500);
	int5 = setInterval("inspiracje(5)",9000);
	int6 = setInterval("inspiracje(6)",8000);
	int7 = setInterval("inspiracje(7)",10000);
	int8 = setInterval("inspiracje(8)",8500);
	int9 = setInterval("inspiracje(9)",11000);
	
	$('ul.done li img').mouseover(function(){
		$('#bottom_'+this.id).slideDown("slow");
		$('#top_'+this.id).slideDown("slow");
		$('#'+this.id+"_descr").fadeTo('slow', 1.0); 
	});
	
	$('ul.done li img').mouseout(function(){
		$('#bottom_'+this.id).slideUp("slow");
		$('#top_'+this.id).slideUp("slow");
		$('#'+this.id+"_descr").fadeTo('slow', 0.3);

	});
	
	
	if ($('#form_contact')!==null){
		$("#form_contact :input").tooltip({
			tipClass: 'tooltipform',

		// place tooltip on the right edge
		position: "center right",

		// a little tweaking of the position
		offset: [-2, 10],

		// use the built-in fadeIn/fadeOut effect
		effect: "fade",

		// custom opacity setting
		opacity: 0.7

	});
	
	}
	$("img#th_mies1[rel]").overlay();
	$("img#th_mies2[rel]").overlay();
	
	$(function() {
	$("img#th_dora[rel]").overlay({effect: 'apple'});
	$("img#th_mw[rel]").overlay({effect: 'apple'});
	$("img#th_jk[rel]").overlay({effect: 'apple'});
	$("img#th_elecom[rel]").overlay({effect: 'apple'});
});
	
	if ($('#actual')!==null){
	
	
		$("#our_mission[title]").tooltip({
		// tweak the position
		   offset: [10, 2],
		   tipClass: 'tooltipmission',
		// use the "slide" effect
		   effect: 'slide'
			// add dynamic plugin with optional configuration for bottom edge
		}).dynamic({ bottom: { direction: 'down', bounce: true } });
		
		
		$("#our_phone[title]").tooltip({
		// tweak the position
		   offset: [10, 2],
		// use the "slide" effect
		   effect: 'slide'
			// add dynamic plugin with optional configuration for bottom edge
		}).dynamic({ bottom: { direction: 'down', bounce: true } });


		$("#our_question[title]").tooltip({
		// tweak the position
		   offset: [10, 2],
		// use the "slide" effect
		   effect: 'slide'
			// add dynamic plugin with optional configuration for bottom edge
		}).dynamic({ bottom: { direction: 'down', bounce: true } });

		$("#our_price[title]").tooltip({
		// tweak the position
		   offset: [10, 2],
		// use the "slide" effect
		   effect: 'slide'
			// add dynamic plugin with optional configuration for bottom edge
		}).dynamic({ bottom: { direction: 'down', bounce: true } });

		$("img#img_actual").mousewheel(function(event, delta) {
   		    event.preventDefault();
			scr+=delta;
			if (scr<0){
				scr=8+scr;
			}
			scr%=8;
			
			$('div.page').animate({
				opacity: 0.4,
				fontSize: "14px", 
				background: "none"
			  }, 100 , 'linear', function() {
				  $(this).css('background','none');
				  $(this).css('font-weight','400');
			  });
			  
			$("#page"+scr).animate({ 
				opacity: 1,
				fontSize: "+=3px", 
			}, 100 , 'linear', function() {
				  $(this).css('background','#2dcbe8');
				  $(this).css('font-weight','600');
			});
			$('img#img_actual').attr("src", "http://evomedia.pl/images/commercials/"+scr+".jpg");
			$('a#link_commercial').attr("href",link[scr]);
			time=0;
		});
		
		$("#page0").css('opacity','1');
		$("#page0").css('font-size','15px');
		$("#page0").css('background','#2dcbe8');
		$("#page0").css('font-weight','600');
	
		setInterval('scroller()',30000);
		setInterval('timer()',100);
		
		$('div.page').click(function(){
			animate_numbers(this);
		});
	}


  $('a.business').click(function(ev)
  {
  	ev.preventDefault();
    /*$('#loader').show();*/
    $('#examples').load(
		this.href,
        { /*query: this.value + '*'*/ },
        function() { /*$('#loader').hide();*/ }
    );
	str = this.href;
	first = str.substring(0,str.lastIndexOf("#"));
	second = str.substring(str.lastIndexOf("/")+1,str.length);
	window.location = first+"#"+second;

  });
});

function animate_numbers(page){
	$('div.page').animate({
		opacity: 0.4,
		fontSize: "14px"
		/*background: "none"*/
	  }, 100 , 'linear', function() {
		  $(this).css('background','none');
		  $(this).css('font-weight','400');
	  });
	  
	$(page).animate({ 
		opacity: 1,
		fontSize: "+=3px", 
	}, 100 , 'linear', function() {
		  $(this).css('background','#2dcbe8');
		  $(this).css('font-weight','600');
	});
	
	num = page.id;
	scr= num.substring(4,5);
	time=0;
	$('img#img_actual').attr("src", "http://evomedia.pl/images/commercials/"+scr+".jpg");
	$('a#link_commercial').attr("href",link[scr]);
}

function timer(){
	t=(300-time)/10;
	t = ( (300-time)/10 < 10 ? "0" : "" ) + t;
	t = ((300-time)%10==0?t+".0":t);
	$('#time').html(t);
	time=++time%300;
}

function scroller(){
	if ($('#actual')!==null){
		$('img#img_actual').fadeTo('slow', 0.5, function() {
			$('img#img_actual').attr("src", "http://evomedia.pl/images/commercials/"+scr+".jpg");
			$('a#link_commercial').attr("href",link[scr]);
			$('img#img_actual').fadeTo('slow', 1, function() {});
			time=0;
		});
		
		
	
	
		
		scr=++scr%8;
				$('div.page').animate({
		opacity: 0.4,
		fontSize: "14px", 
		background: "none"
	  }, 100 , 'linear', function() {
		  $(this).css('background','none');
		  $(this).css('font-weight','400');
	  });
	  
	$("#page"+scr).animate({ 
		opacity: 1,
		fontSize: "+=3px", 
	}, 100 , 'linear', function() {
		  $(this).css('background','#2dcbe8');
		  $(this).css('font-weight','600');
	});
	}
}

function rand ( )
{
	a = Math.random ( );
  return ( Math.floor ( a * 9000 + 3000 ) );
}

function inspiracje(id){
		$('#scroll_'+id).data("scrollable").next();		
		if (id==1){
			clearInterval(int1);
			int1 = window.setInterval('inspiracje("'+id+'")', rand());
		}
		if (id==2){
			clearInterval(int2);
			int2 = window.setInterval('inspiracje("'+id+'")', rand());
		}
		if (id==3){
			clearInterval(int3);
			int3 = window.setInterval('inspiracje("'+id+'")', rand());
		}
		if (id==4){
			clearInterval(int4);
			int4 = window.setInterval('inspiracje("'+id+'")', rand());
		}
		if (id==5){
			clearInterval(int5);
			int5 = window.setInterval('inspiracje("'+id+'")', rand());
		}
		if (id==6){
			clearInterval(int6);
			int6 = window.setInterval('inspiracje("'+id+'")', rand());
		}
		if (id==7){
			clearInterval(int7);
			int7 = window.setInterval('inspiracje("'+id+'")', rand());
		}
		if (id==8){
			clearInterval(int8);
			int8 = window.setInterval('inspiracje("'+id+'")', rand());
		}
		if (id==9){
			clearInterval(int9);
			int9 = window.setInterval('inspiracje("'+id+'")', rand());
		}
}

