//SMOOTH SCROLL FOR IN-PAGE LINKS
$(document).ready(function () {
	$.localScroll({
    	offset:-64,
    	duration:350
	});
});	



//SERVICES TAB---------------------------------------------------------
var servicesVisible=0;

function hideServices(){
	$('#ui').hide();
	$('#vc').hide();
	if (servicesVisible==1){
		servicesVisible=0;
		$("#servicescollapsing").slideUp(500);	
	}
}
$(document).ready(function () {
	hideServices();	
});	


var selectedServicesSub="none";
var servicesActiveTab="none";

var noflashmenu=0;
function showServiceSub(clickedTab){
	/*Firefox 3.6 has some weird rendering bug, so redraw is needed*/
	$("#home #homeflash #smenu").css('background-color', '#fffffe' );
	setTimeout(function() {
			   	$("#home #homeflash #smenu").css('background-color', '#ffffff' );
   	}, 1000);

	if (servicesActiveTab != clickedTab){
		servicesActiveTab=clickedTab;
		if (clickedTab=="ui"){
			selectedServicesSub="ui";
			$('#services #vc').hide();
			$('#services #ui').show();
			//IE MAKES FONTS LOOK BAD IF OPACITY IS USED
			if (!jQuery.browser.msie){
				$("#services #ui").animate({ 	opacity: 0}, { duration: 0 });
				$("#services #ui").animate({ 	opacity: 1}, { duration: 500, queue: true });
			}
			$("#home #nflinkui").addClass('selected');
			$("#home #nflinkvc").removeClass('selected');
			setTimeout(function() {
	   			$.ga.trackEvent("tabs", "ui");
   			}, 2500);
		}
		if (clickedTab=="vc"){
			selectedServicesSub="vc";
			$('#services #ui').hide();
			$('#services #vc').show();
			if (!jQuery.browser.msie){
				$("#services #vc").animate({ 	opacity: 0}, { duration: 0 });
				$("#services #vc").animate({ 	opacity: 1}, { duration: 500, queue: true });
			}
			$("#home #nflinkvc").addClass('selected');
			$("#home #nflinkui").removeClass('selected');
			setTimeout(function() {
	   			$.ga.trackEvent("tabs", "vc");
   			}, 2500);
		}
		callToActionscript("homeflash", clickedTab);

		activeLink="services";
	}
	//$(window).scrollTo(320, 400 );
	if (noflashmenu==0){
		$(window).scrollTo('#servicesstart', 400, {offset: -64} );
	}
}



// MENU CLICK OPENS 1ST TAB
$(function(){
	$("#menu #navi #linkservices").click(function(event) {
		if (selectedServicesSub=="none"){
			showServiceSub("ui");
		}
	});
});
$(function(){
	$("#services #servicesalsoui").click(function(event) {
		showServiceSub("ui");
	});
});
$(function(){
	$("#services #servicesalsovc").click(function(event) {
		showServiceSub("vc");
	});
});



//NO FLASH SELECTION OPENS TABS
$(function(){
	$("#home #nflinkui").click(function(event) {
		noflashmenu=1;
	    setTimeout(function() {
	    	showServiceSub("ui");
		}, 50);
	});
	$("#home #nflinkvc").click(function(event) {
		noflashmenu=1;
		setTimeout(function() {
	    	showServiceSub("vc");
		}, 50);
	});
});





//AS-JS COMMUNICATION---------------------------------------------
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function callToActionscript(flash, state) {
	getFlashMovie(flash).sendToActionscript(state);
}
var flashLoaded=0;
quedTab="";
function sendToJavaScript(val){
	if (val=="loaded"){
		//IF TAB OPEN IS QUED
		if (servicesActiveTab!="none"){
			callToActionscript("homeflash", servicesActiveTab);
		}
		flashLoaded=1;
	}else {
		showServiceSub(val);
	}
	
}



//COLLAPSING ELEMENTS BASED ON CLASS-----------------------------
var chosen="";
$(document).ready(function() {

  //hide the all of the element with class collapsing_body
  $("#services_examples .collapsing_body").hide();
 
 
 //SERVICES UI
  //toggle the componenet with class collapsing_body
  $("#services_examples .collapsing_head").click(function(){
    $(chosen).removeClass('open');
    chosen = this;
    state = $(chosen).next(".collapsing_body").css('display'); 
    $("#services_examples .collapsing_body").slideUp(100); 
     
    if (state=="none"){
    	setTimeout(function() {
    	//alert(state);
    		$(chosen).addClass('open');
    		$(chosen).next(".collapsing_body").slideDown(100);

    	}, 150);
    }  
  });

});


//COLLAPSING ELEMENTS BASED ON DIV------------------------------
clicked="";
choosen2="";
var benchmark=0;
$(document).ready(function(){
	//hide the all of the elements
	$("#references .refpage").hide();
	$("#references #zoom").hide();
	$("#references #zoom").click(function(){
		showRefNavi();
	});
	$("#references #reflinks .thumb a").click(function(){ 
		chosen2 = this;
		clicked=$(this).attr("class");
		clickedname=$(this).attr("id");
		//hide navigation
		if (navistate=="navion"){
			hideRefNavi();
		}
		//link styles
		$("#references #reflinks .thumb a img").removeClass("selected");
		$("."+clicked+" img").addClass("selected");
		//swap page
    	swapPage(clicked, clickedname);
	});
});



//REFERENCES NAVIGATION--------------------------------------------
function swapPage(page, name){
	$('#references #refpages').animate({ height: 333 }, 300 );
	if (jQuery.browser.msie){
		$("#references .refpage").slideUp(300); 
	} else {
		$("#references .refpage").fadeOut(300);
	}
  	setTimeout(function() {
  		if (jQuery.browser.msie){
			$("#"+page).slideDown(500); 
		} else {
			$("#"+page).fadeIn(500);
		}   		
    }, 300);
    //ANALYTICS
	setTimeout(function() {
	    $.ga.trackEvent("tabs", name);
    }, 2500);
}



navistate="navion";
function hideRefNavi(){
	navistate="navioff";
	$("#references #reflinks .thumb a img").addClass("small");
	$("#references #reflinks div").css('margin', '0px 15px 5px 0px' );
	$("#references #reflinks div a img").animate({ width: "60px", height: "60px" }, 300 );
	$("#references #reflinks div a span").animate({ width: "0px", height: "0px" }, 0 );
	$("#references #reflinks div a span").css('display', 'none' );
	$("#referencelinks div#disclaimer").fadeOut(150);
	setTimeout(function() {
   		$("#references #zoom").show();
   		$("#references #zoom").css('visibility', 'visible' );
    }, 150);
}


function showRefNavi(){
	navistate="navion";
	$("#references #reflinks .thumb a img").removeClass("selected");
	$("#references #reflinks .thumb a img").removeClass("small");	

	$("#references #reflinks div").css('margin', '0 30px 15px 0' );
	$("#references #reflinks div a img").animate({ width: "150px", height: "150px" }, 300 );
	$("#references #reflinks div a span").animate({ width: "150px", height: "30px" }, 300 );
	setTimeout(function() {
		$("#references #reflinks div a span").css('display', 'block' );
   		$("#references #zoom").hide();
   		$("#referencelinks div#disclaimer").fadeIn(150);
    }, 100);
    
    $('#references #refpages').animate({ height: '0px' }, 300 );
    $("#references .refpage").slideUp(100); 
    
}




$(document).ready(function() {
	setTimeout(function() {
		//SHOW BODY ONLY AFTER MOST STUF IS LOADED
		$("body.js").css('visibility', 'visible' );
		//START PRELOADING
		$("#references #refpages").cdzPreloadImages(function(total){},
			function(loaded, total){}, 
			function(){} );
	}, 500); 
	//LOAD ANALYTICS
	setTimeout(function() {
		$(document).ready( function() { $.ga.load("UA-12834624-1"); } );
	}, 1000);
	//REPLACE EMAIL
	setTimeout(function() {
		$("#contact #mailfoo1").css('display', 'none' );
		$("#contact #mailfoo2").css('display', 'block' );
		$("#contact #mailfoo2").attr('href', $("#contact #mailfoo2").attr('href').replace("firstname", "niko"));
	}, 500);
	//CHANGE SERVICE HEADLINES FOR JAVASCRIPT ENABLED USERS
	$('#services #ui #uihead').html('Things that click');
	$('#services #vc #vchead').html('Show it');

	//SAFARI 4 MIGHT HAVE PROBLEMS DISPLAYING CORBEL BOLD, SO
	if( $.browser.safari ){
		$('*').css('font-weight', 'normal !important' );
	}	
});

