var cur='hello',win_h,win_w,ct,cl,is_m,tops=0,lefts=0,curwor='#work-intro',trigger;

swfobject.embedSWF("swf/flame.swf","flash-home","250","367","9.0.0","",{},{wmode:'transparent'},{});

$(document).ready(function () {
	win_h=$(window).height();
	win_w=$(window).width();
	if(win_h<500) is_m=true;
	
	$('#hello').fadeIn();
	place();
	scrollIt();
	$('.sliding').click(function(){
		if($(this).hasClass('up')) var nd=-50;
		if($(this).hasClass('down')) var nd=50;
		var ttop=$(this).parent().position();
		ttop=ttop.top;
		ntop=ttop+nd;
//		alert(ttop+' '+ntop);
		$(this).parent().animate({top:ntop},500);
	});
    $('#work a.swap').click(function(){
		var nwor=this.hash;
		$(curwor).slideUp('fast',function(){ $(nwor).slideDown('fast') });
		curwor=nwor;
	});
    $('.in_page').click(function(e){
		e.preventDefault();
		
		$('#'+cur).fadeOut(500);
		cur=$(this).html();
		$('#'+cur).fadeIn(500);
		pos=$(this).attr('rel');
		pos=pos.split(',');
		ct=pos[0];
		cl=pos[1];
		tops=pos[0];
		lefts=pos[1];
		tops=-(tops-win_h-10);
		lefts=-(lefts-win_w);
		if(pos[0]==0) tops=0;
		if(pos[1]==0) lefts=0;
		scrollIt();
    });
	$(window).smartresize(function(){ place(); });
//	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod'){
//	};
	$(".f_image").fancybox();
    $(".f_audio").fancybox({
		'overlayShow'		: false,
        'padding'           : 0,
        'autoScale'         : false,
		'width'				: 250,
		'height'			: 100,
        'transitionIn'      : 'none',
        'transitionOut'     : 'none'
    });	
	$(".f_video").click(function() {
		$.fancybox({
			'overlayShow'	: false,
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 860,
			'height'		: 480,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
				'wmode'				: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});
		return false;
	});
	if(trigger) $('.trig_vid').click();
});

function scrollIt(){
	win_h=$(window).height();
	win_w=$(window).width();
	tops=ct;
	if(is_m && tops==1900) tops=1700;
	lefts=cl;
	tops=-(tops-win_h-10);
	lefts=-(lefts-win_w);
	if(ct==0) tops=0;
	if(cl==0) lefts=0;
	window.status=win_h;
	if(win_h<615) $('#footer').fadeOut('slow');
	else $('#footer').fadeIn('slow');
//	if(win_h<570) $('.sliding').fadeIn('slow');
//	else $('.sliding').fadeOut('slow');
	if(tops || tops==0) $('#scroll_outer').animate({top:tops, left:lefts},1500);
//	$('#scroll_outer').animate({
//	  scrollTop: tops,
//	  scrollLeft: lefts
//	}, 1500);
}

function place(){
	scrollIt();
	if(is_m) d_var=-200; else d_var=0;
	$('#hello').animate({left:($(window).width()/2-315), top:120}, 500);
	$('#clients').animate({left:($(window).width()/2-315), top:(1900-$(window).height()+110+d_var)}, 500);
	$('#work').animate({left:(2400-($(window).width()/2)-315), top:120}, 500);
	$('#contact').animate({left:(2400-($(window).width()/2)-315), top:(1900-$(window).height()+110+d_var)}, 500);
};

//smart resize
(function($){var event=$.event,resizeTimeout;event.special["smartresize"]={setup:function(){$(this).bind("resize",event.special.smartresize.handler);},teardown:function(){$(this).unbind("resize",event.special.smartresize.handler);},handler:function(event,execAsap){var context=this,args=arguments;event.type="smartresize";if(resizeTimeout)
clearTimeout(resizeTimeout);resizeTimeout=setTimeout(function(){jQuery.event.handle.apply(context,args);},execAsap==="execAsap"?0:100);}}
$.fn.smartresize=function(fn){return fn?this.bind("smartresize",fn):this.trigger("smartresize",["execAsap"]);};})(jQuery);
