var is_inMeta = false;
var metaHeight = 0;
var scrollableAPI;
var backgroundImageURL;

jQuery(document).ready(function() {

	if(!jQuery('#backgroundvideo').length > 0 && !jQuery('#f-backgroundvideo').length > 0){
		jQuery(".bgstretcher").hide();
		jQuery.backstretch(backgroundImageURL, {speed: 150});
	}

// For use within normal web clients 
var isTouch = ('ontouchstart' in window);
if(!isTouch){if(jQuery("form.jqtransform").length > 0 ){ jQuery("form.jqtransform").jqTransform(); }}
			
// Autoplay Video

if ( jQuery(".scrollable").length > 0) {
	
	jQuery('.prev').hide().removeClass("clickable").animate({ opacity: 0 });
	jQuery('.next').hide().removeClass("clickable").animate({ opacity: 0 });
	
	jQuery('.prev').hover(function(){
		if(jQuery(this).is(':visible')){
			jQuery(this).stop().animate({ opacity: .9 });
		}
	},function(){
		if(jQuery(this).is(':visible')){
			jQuery(this).stop().animate({ opacity: 0 });
		}
	});
	
	jQuery('.next').hover(function(){
		if(jQuery(this).is(':visible')){
			jQuery(this).stop().animate({ opacity: .9 });
		}
	},function(){
		if(jQuery(this).is(':visible')){
			jQuery(this).stop().animate({ opacity: 0 });
		}
	});
    
    /* JQUERY TOOLS STUFF */ 
	scrollableAPI = jQuery(".scrollable").scrollable({ api: true });
				
	var allScrollables = scrollableAPI.getItems();
	scrollableAPI.begin();
	scrollableAPI.onSeek(function(event) {
		if(jQuery(allScrollables[this.getIndex()]).outerHeight() > 10){ var listItemElement = jQuery(allScrollables[this.getIndex()]).outerHeight();}
		else if(jQuery(allScrollables[this.getIndex()]).outerHeight().children() > 10){ var listItemElement = jQuery(allScrollables[this.getIndex()]).children().outerHeight();}
		jQuery('.scrollable').animate({ height : listItemElement }, function(){
			resizeContent();
		});
		jQuery('.project-thumbs li').css('border', "2px solid transparent");
		jQuery('.project-thumbs li').eq(scrollableAPI.getIndex()).css('border', "2px solid yellow");
		if(scrollableAPI.getIndex() == 0){ jQuery('.prev').hide().removeClass("clickable").animate({ opacity: 0 });jQuery('.next').show().addClass("clickable");}
		else if(scrollableAPI.getIndex()+1 == scrollableAPI.getSize()){jQuery('.next').hide().removeClass("clickable").animate({ opacity: 0 }); jQuery('.prev').show().addClass("clickable");}
		else{
			jQuery('.prev').show().addClass("clickable");
			jQuery('.next').show().addClass("clickable");
		}
		if(scrollableAPI.getSize() == 1){
			jQuery('.prev').hide().removeClass("clickable");
			jQuery('.next').hide().removeClass("clickable");
		}
	});
			
}

	if ( jQuery("#masonry").length > 0) {
		jQuery('#masonry').masonry({
			singleMode: false, 
			itemSelector: '.module',
			animate: true},
			function() {
				jQuery(".module").fadeIn(100);
			}
		);	
	}

	//jQuery("div.menu_head").toggle(function() { hideMenu();}, function() { showMenu(); });
	//jQuery("div.menu_head a").toggle(function() { hideMenu();}, function() { showMenu(); });
	
	if ( jQuery(".front-news").length > 0) {	
		// FADE IN EACH NEWS IDEM
		jQuery('.feature-1').fadeIn(900, function() {
			jQuery('.feature-2').fadeIn(900, function() {
       			jQuery('.feature-3').fadeIn(900, function() {
       				jQuery('.feature-4').fadeIn(900, function() {
       		
      				});
      			});
      		});
      	});
	}
	
	
});


/* MENU */ 

function showMenu() {
 jQuery(".menu_body").stop().animate({opacity: "100%", height: 220}, 300); 
 jQuery(".menu_body").css("z-index","99");
 jQuery(".inside-menu").stop().animate({marginTop: 40}, 300); 
 jQuery('.menu_head').css('backgroundPosition', "0px -16px");
}

function hideMenu() { 
 jQuery(".menu_body").stop().animate({opacity: 0, height: 0}, 300); 
 jQuery(".inside-menu").stop().animate({marginTop: 50}, 300); 
 jQuery('.menu_head').css('backgroundPosition', "0px 0px");
}



function resizeContent(){
	if(jQuery('#content').is(':hidden')){
		jQuery('#content').show();
	}
}

/* VIDEO */
jQuery(window).resize(function() {
	resizeContent();
});


function goToMedia(item){
	scrollableAPI.seekTo(jQuery('.project-thumbs li').index(item));
}


/* WORK / PROJECT PAGE SCRIPT */
jQuery('.project-module').hover(projectDown, projectUp);
function projectDown(){ jQuery(this).find('.project-module-image').stop().animate({ top: '53px' },100); jQuery(this).find('.project-module-title').css("color","#FFFF00");}
function projectUp(){ jQuery(this).find('.project-module-image').stop().animate({ top: '33px' },100); jQuery(this).find('.project-module-title').css("color","#FFFFFF");}
