﻿function onAfter() { 
	var i=0;
	$('#dlbox img').each(function(index){
		if ($(this).css('display')=='block')
		i=index+1;
	});
    $('#dl1').attr('href','http://www.winsoftinvent.ro/img/download/desktop/wall'+i+'_1600_900.jpg');
	$('#dl2').attr('href','http://www.winsoftinvent.ro/img/download/desktop/wall'+i+'_1280_1024.jpg');
}

$(document).ready(function() {
	/* TIMELINE */
	var wl=$(window).width()-$('#timeline .box').width();
	$('#timeline .box').draggable({ axis: 'x',containment: [wl,0,0,0] });
	$(window).resize(function(){
		wl=$(window).width()-$('#timeline .box').width();
		if ($(window).width()<965) wl=965-$('#timeline .box').width();
		$('#timeline .box').draggable('option', 'containment', [wl,0,0,0]);
	});
	$('.box a').hover(
		function()
			{$('img',this).attr('src',$('img',this).attr('src').replace("-off","-on"));$('img',this).css('margin','-3px 0px 0px -3px');},
		function()
			{$('img',this).attr('src',$('img',this).attr('src').replace("-on","-off"));$('img',this).css('margin','0px');}
	);
	 $('.box a').click(function () { 
      $('img',this).attr('src',$('img',this).attr('src').replace("-off","-on"));$('img',this).css('margin','-3px 0px 0px -3px');
    });


	
	/* CUFON */	
	Cufon.replace('h1',{hover: true});
	Cufon.replace('h2',{hover: true});
	Cufon.replace('h3',{hover: true});
	Cufon.replace('h5',{hover: true});
	Cufon.replace('.intro-name',{hover: true});
	Cufon.replace('.intro-quote',{hover: true});	
	Cufon.replace('.content-box.portfolio div.text a',{hover: true});
	Cufon.replace('.content-box.portfolio div.list a',{hover: true});
	
	/* LIMIT <p> LENGTH on content pages*/	
	$('p.alg').each( function(){
		$(this).prepend('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
	});	
	
	
	/* HEADER MAIN MENU */	
	$('#header>ul>li').each(function(i){	
		$(this).bind('mouseenter',function(){
			if ($(this).hasClass('now'))
				return false;
			else{
				$('img.on',this).stop(true , true) .fadeIn(1000);
				$('img.off',this).stop(true , true) .fadeOut(1000);
			}
		});
		$(this).bind('mouseleave',function(){
			if ($(this).hasClass('now'))
				return false;
			else{
				$('img.on',this).stop(true , true) .fadeOut(1000);
				$('img.off',this).stop(true , true) .fadeIn(1000);
			}
		});
	});	
	
	
	/* HEADER MENU ABOUT */
	$('#header li').eq(0).toggle(
		function(){
			if ($('#portfolio').is(':visible')) $('#header li').eq(2).click();
			$('#about').fadeIn('slow', function() {if(jQuery.browser.msie) this.style.removeAttribute('filter')});
        },function() {
			$('#about').fadeOut('slow', function() {if(jQuery.browser.msie) this.style.removeAttribute('filter')});
        });
	$('#about li')
		.css( {backgroundPosition: "-50px 0px"} ) 
		.mouseover(function(){$(this).stop().animate({backgroundPosition:"(50% 0px)"}, {duration:500})}) 
		.mouseout(function(){$(this).stop().animate({backgroundPosition:"(-50px 0px)"}, {duration:500})}) 
	if ($('#about').hasClass('on')){$('#header li').eq(0).click()};
	
	
	/* HEADER MENU PORTFOLIO */
	$('#header li').eq(2).toggle(
		function(){
			if ($('#about').is(':visible')) $('#header li').eq(0).click();
			$('#portfolio').fadeIn('slow', function() {if(jQuery.browser.msie) this.style.removeAttribute('filter')});
			
        },function() {
			$('#portfolio').fadeOut('slow', function() {if(jQuery.browser.msie) this.style.removeAttribute('filter')});
        });
	$('#portfolio li')
		.css( {backgroundPosition: "-50px 0px"} ) 
		.mouseover(function(){$(this).stop().animate({backgroundPosition:"(50% 0px)"}, {duration:500})}) 
		.mouseout(function(){$(this).stop().animate({backgroundPosition:"(-50px 0px)"}, {duration:500})}) 
	if ($('#portfolio').hasClass('on')){$('#header li').eq(2).click()};
	
	
	/* DOWNLOAD ANIMATION*/		
	$('#dlbox').cycle({
		fx:   'shuffle', 
		shuffle: { 
			top:  -30, 
			left:  30 
		}, 
		easing: 'easeInSine',
		speed: 600,
		delay: -2000 ,
		timeout: 0, 
		next:   '#dlbox-prev', 
		prev:   '#dlbox-next',
		after: onAfter 
	});
		
		
	/* SERVICES ANIMATION*/	
	$('#services-box').cycle({
		fx:      'custom', 
		sync: 1, 
		cssBefore: {  
			top:  0, 
			left: -600, 
			display: 'block'  
		}, 
		animIn:  { 
			left: 0 
		}, 
		animOut: {  
			top: 600 
		}, 
		speed: 400,		
		timeout: 0 ,
		pager:  '#sthumbs'
	});
	$('#sthumbs a').each(function(i){
		$(this).html('<img src="img/services/thumb'+(i+1)+'.jpg" alt=""/>');
	});

	
	/* SITEMAP */	
	$('#footer .sitemap li').animate({'marginTop':'-60'},0);
	$('#footer h5').toggle(
		function(){
			$('#footer .sitemap li').animate({'marginTop':'0'},1000);$(window).scrollTo('100%',800);
        },function() {
			$('#footer .sitemap li').animate({'marginTop':'-60'},1000);$(window).scrollTo('0%',800);
    });	
	
	
	/* IMAGE HOVER */
	$('img.hover').hover(
		function()
			{this.src = this.src.replace("-off","-on");},
		function()
			{this.src = this.src.replace("-on","-off");}
	);
	
	$('a.hover').hover(
		function()
			{$('img',this).attr('src',$('img',this).attr('src').replace("-off","-on"));},
		function()
			{$('img',this).attr('src',$('img',this).attr('src').replace("-on","-off"));}
	);
	
	/* PORTFOLIO FANCYBOX */
	$(".content-box.portfolio div.text a").fancybox({
		'zoomSpeedIn':		600, 
		'zoomSpeedOut':	600, 
		'overlayShow':		false,
		'padding': 0,
		'easingIn' : 'easeOutBack',
		'easingOut' : 'easeInBack' 
	});
	
});
