//YOUTUBE API
google.load("swfobject", "2.1");

function loadVideo() {        
	var videoID = "4Ay46STAza0"
	var params = { allowScriptAccess: "always", wmode:'transparent' };
	var atts = { id: "ytplayer", wmode:"transparent" };
	swfobject.embedSWF("http://www.youtube.com/v/" + videoID + "&enablejsapi=1&playerapiid=player1", "video", "450", "330", "8", null, null, params, atts);	
};

function loadVideo2() {        
	var videoID = "bTZU5CCU4Y0"
	var params = { allowScriptAccess: "always", wmode:'transparent' };
	var atts = { id: "ytplayer", wmode:"transparent" };
	swfobject.embedSWF("http://www.youtube.com/v/" + videoID + "&enablejsapi=1&playerapiid=player1", "video_iphone", "450", "330", "8", null, null, params, atts);	
};

function loadVideo3() {        
	var videoID = "xKqNox4Y8aw"
	var params = { allowScriptAccess: "always", wmode:'transparent' };
	var atts = { id: "ytplayer", wmode:"transparent" };
	swfobject.embedSWF("http://www.youtube.com/v/" + videoID + "&enablejsapi=1&playerapiid=player1", "video_cpp", "450", "330", "8", null, null, params, atts);	
};

google.setOnLoadCallback(loadVideo2);
google.setOnLoadCallback(loadVideo);
google.setOnLoadCallback(loadVideo3);


//USERFLY
var userflyHost = (("https:" == document.location.protocol) ? "https://secure.userfly.com" : "http://asset.userfly.com");
document.write(unescape("%3Cscript src='" + userflyHost + "/users/24393/userfly.js' type='text/javascript'%3E%3C/script%3E"));

document.addEvent("domready",function(){
	function scrollPage(ele, horizontal){
	
		if(horizontal == undefined) horizontal = true;
		
		var target = $(ele);
		
		if(target == null) return false;
		
		var container = target.getElement('.scrollContainer');
		var panels = container.getElements('div');
		var scroll = target.getElement('.scroll');
		
		target.setStyle('position','relative');
		container.setStyle('position','relative');
		
		if (horizontal) {
			//alert(ele + " horizontal");
	        panels.setStyle('float',"left");
	        panels.setStyle('position','relative');
	        var w = panels[0].getSize().x * panels.length ;
	        container.setStyle('width', w);
	     	//alert(container.getStyle('width'));   
	    }
	    
	   	scroll.setStyle('position','relative')
	    scroll.setStyle('overflow', 'hidden'); 
		
		var navigations = target.getElement('.navigation').getElements('a');
		
		
		var scrollFx = new Fx.Scroll(scroll,{
					wheelStops:false,
					duration:700,
					wait:false,
					offset: {x:-1, y:0},
					transition: Fx.Transitions.Sine.easeOut
				});

		
		navigations.each(function(nav, i){
			nav.addEvent('click',function(ev){
				ev.stop();
				setTab(nav);
			})
		});
		
		function setTab(nav){
			if(nav == '') return false;
			
			navigations.removeClass("selected");
			nav.addClass("selected");
			
			var elename = String(nav.get('href'));
			elename = elename.substring(1);
			scrollFx.toElement(elename);
			
			var	parent = nav.getParent('.panel');
			
			if(parent != '' && parent != null ){
				if(nav.getParent('.panel').get('id') == 'features'){
					($('tabnav').getElements('a').removeClass("selected"));
					var nav = $('tabnav').getElement('a[href$=features]');
					nav.addClass('selected')
				}
			}
			
			return true;
		}
		
		var n = navigations.filter(function(item, i){
			return item.hash == window.location.hash; 
		});
		
		
		if(!setTab(n)) navigations[0].addClass('selected');
		
	}

	//scrollPage('featured-slideshow');
	scrollPage('slider');
	scrollPage('content');
	scrollPage('features-slides', false);
	scrollPage('clique-slides', false);
	
	//centerlize navigation
	var navigation = $('content').getElement('.navigation');
	var n_width = (navigation.getSize().x);
	var l = (960-n_width) * 0.5;
	navigation.setStyle('left', l);
	
	
	//hide featured controller
	var featnav = $("featured-nav");
	var featcont = $("slider");
	
	var myFx = new Fx.Tween("featured-nav",{
		transition: Fx.Transitions.Back.easeOut
	});
	
	featcont.addEvent('mouseover',function(ev){
		myFx.cancel();
		myFx.start('margin-top',-45);
	});
	
	featcont.addEvent('mouseout',function(ev){
		myFx.cancel();
		myFx.start('margin-top',-100);
	});
	
	myFx.set('margin-top',-100);
	(function(){ myFx.start('margin-top',-50);}).delay(1000);
	(function(){ myFx.start('margin-top',-100);}).delay(2000);
	
	//	REMOOZ
	ReMooz.assign('.thumb a', {
		'origin': 'img',
		'shadow': 'onOpenEnd', // fx is faster because shadow appears after resize animation
		'resizeFactor': 0.8, // resize to maximum 80% of screen size
		'cutOut': false, // don't hide the original
		'opacityResize': 0.4, // opaque resize
		'dragging': false, // disable dragging
		'centered': true // resize to center of the screen, not relative to the source element
	});

	var tag = $('hire-tag');
	var tagFx = new Fx.Tween(tag,{
		transition: Fx.Transitions.Back.easeOut
	});
	
	window.addEvent('scroll',function(e){
		var offset = 70;
		var timer ;
		
		var ty = window.getScroll().y - offset;
		var ttop = tag.getStyle('top').toInt() - offset;
		
		tagFx.cancel();
		$clear(timer);
		
		if(ty < ttop){
			
			tag.setStyle('top', ty - offset);
			animateTag();
		}else{
			timer = animateTag.delay(500);
			
		}
		
		function animateTag(){
			ty = window.getScroll().y - offset;
			tagFx.start('top',ty);
		}
	});
	
	window.fireEvent('scroll');
	
	window.addEvent('resize', function(e){
		repositionTag();
	})
	
	function repositionTag(){
		var sw = (document.body.getSize().x);
		
		if(sw < 1024){
			tag.setStyle('left',sw - 200);
		}else{
			tag.setStyle('left',950);
		}
		
	}
	
	repositionTag();
})