/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
            
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);



// Hides

$(document).ready(function(){
	$('#homepage-text div').hide();
	$('#newsitems').cycle({timeout: 6000});
	
	//Portfolio
	var offset = 0;
	$('#slides li').each(function(){
		$(this).css({
			left: offset + 'px'
		});
		offset += 650;
	});
	//thumbnail hover
	$('#thumbs li a').each(function(){
		//remove link
		$(this).removeAttr('href');
		$('<div>&nbsp;</div>').css({
			opacity: .5			
		}).hover(function(){
			$(this).css('opacity', 0);
		},function(){
			$(this).css('opacity', .5);
		}).appendTo(this);
	});
	
	offset = 0;
	$('#thumbs li').each(function(){
		$(this).css({cursor: 'pointer'});
		
			
		$(this).data('animate', { left: offset + 'px' });
		offset -= 650;
		$(this).click(function(){
			$('#slides').animate($(this).data('animate'));
		});
	});
	
	//Testimonials
	$('#testimonials').cycle({timeout: 10000});
	
});


// Page Load Animations
if(app == 'home'){
	$(window).load(function(){
		$('#logo.home').css({backgroundPosition: '0px -175px'});
		$('#mailbox.home').css({backgroundPosition: '0px 151px'});
		$('.home').animate(
			{ backgroundPosition: "(0px 0px)" },
			800
		);
		var speed = 250;
		$('#home-we').fadeIn(speed, function(){
			$('#home-deliver').fadeIn(speed, function(){
				$('#home-your').fadeIn(speed, function(){
					$('#home-message').fadeIn(speed);
				});
			});
		});
	});
}

// Cufon Fonts
Cufon.replace('.label', { fontFamily: 'tgbc' });
Cufon.replace('h1', { fontFamily: 'tgbc' });
Cufon.replace('h2', { fontFamily: 'tgbc' });
Cufon.replace('h4', { fontFamily: 'tgbc' });
Cufon.replace('h5', { fontFamily: 'tgbc' });



