var wizardRotation;
var wizardSpeed = 28000;
var wizardScrollSpeed = 2000;
var hologramDelay = 15000;
var holoItemTime = 3000;
var showTime = 1500;

$(window).load(function () {
						 	
	var ref = document.referrer.toLowerCase();
	if(ref.length > 0) {
		showTime = 100;
	}
	
	//show the content after page has been fully loaded
	showWeb();	
	
	//set the header position to center, modify header background position depending on the client screen height
	//resizeHeader()();

	setFooterBgr();	
	wizardSlider();
	
	$('.wrapper').height($('.wrapper').height() - 439);
	$('.wrapper').css({'overflow': 'hidden'});
});


$(document).ready(function(){							   
	loadingOperations();	
	resizeContent();	
	prepareBoxes();	
	holoprojection();	
		
});

$(window).resize(function(){	
	//resizeHeader()();	
	setFooterBgr();
});


/**
2 * jQuery.ScrollTo - Easy element scrolling using jQuery.
3 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
4 * Dual licensed under MIT and GPL.
5 * Date: 5/25/2009
6 * @author Ariel Flesler
7 * @version 1.4.2
8 *
9 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
10 */
(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);


function isFirstLoad() {
		var ref = document.referrer.toLowerCase();
		if(ref.length == 0) {
			return true;
		} else {
			return false;	
		}
}

function loadingOperations() {
	/*
	if (isFirstLoad()) {
		$('body').append('<div class="firstLoad">');
	}
	if (isFirstLoad()) {
		//set pripriet css for fade in effect			
		$('.wrapper > div').css({'display': 'none'});	
		$('.wrapper > div').css({'opacity': 0});	
	} else {
		if ($('body').hasClass('loading'))
			$('body').removeClass('loading');
			
		$('.wrapper').addClass("bg-ocean-repeater");	
	}
	*/
	var loader = $(document.createElement('DIV'));
	var top  = $(document.createElement('DIV'));
	
	loader.addClass('loader');
	top.addClass('top');
	loader.append(top);
	
	
	
	var animLoader = $(document.createElement('DIV'));
	animLoader.addClass('animLoader');
	animLoader.append('<div class="progressBar"></div>')
	animLoader.append('<strong></strong>');
	

	//animLoader.css({'top': 	($('body').height() - 200)/2, 'left': ($('body').width() - 200)/2});
	//JS20101211 fixed from top
	animLoader.css({'top': 	300, 'left': ($('body').width() - 200)/2});
	
	loader.append(animLoader);
	
	
	$('body').append(loader);
	$('.wrapper').addClass("bg-ocean-repeater");
	if ($('body').height() > 1024) {
		$('body').addClass('top');
	}
	
}



function prepareBoxes() {						
						
$('.box').append('<span class="cornerHead left"></span><span class="cornerHead right"></span><span class="border top"></span><span class="corner left"></span><span class="corner right"></span><span class="border bottom"></span><span class="shadow right"></span><span class="shadow top"></span>');						

$('.box.blackbox').each(function(){
		if ($(this).hasClass('left')) {
			if ($(this).next().hasClass('box blackbox')) {
				$(this).next().addClass('right');
			}
		} else if ($(this).hasClass('right')) {
			if ($(this).next().hasClass('box blackbox')) {
				$(this).next().addClass('left');					
			}			
		} else {
			if ($(this).prev().hasClass('box blackbox left')) {
				$(this).addClass('right');							
			} else {
				$(this).addClass('left');	
			}
			
		}
	});
}


function setFooterBgr() {
	/*
	var bgrLeft = Math.floor((1920 - $('body').width())/2);
		
	$('.footer').css({'background-position': '-'+bgrLeft+'px 0'});
	*/
}

function showWeb() {	
	/*
		$('.wrapper').addClass("bg-ocean-repeater");		
		$('body').removeClass('loading');	
		//resizeHeader()();
		setFooterBgr();
		
	if (isFirstLoad()) {	
		$('.firstLoad').fadeOut(1500);	
	}
	*/
	
	//show the content	
	$('.wrapper > div').css({'display' : 'block'}); 
	$('.loader').fadeOut(showTime);
	if (!$.browser.msie) {
			
		$('.wrapper > div').animate({opacity: '1'}, showTime, function(){
		$('.wrapper').addClass("bg-ocean-repeater");
		//.css({'background-image': 'url(../css/images/bg-ocean-repeater.jpg)'});

			$('body').removeClass('loading');	
			//repair header and footer background (due to possible scrollbar existention)
			//resizeHeader()();
			setFooterBgr();
		});		
	} else {
		$('.wrapper').addClass("bg-ocean-repeater");
		//.css({'background-image': 'url(../css/images/bg-ocean-repeater.jpg)'});
		$('body').removeClass('loading');
		
		//repair header and footer background (due to possible scrollbar existention)
		//resizeHeader()();
		setFooterBgr();
	}
		
}

//This functionality is temporariely disabled
function resizeHeader() {

	var clientWidth = $('.header').width();
	var clientHeight = document.body.clientHeight
	var headerHeight = clientHeight - 150;
	var headerContentTop = 0;
	var headerBgr = 0;
	
	var contentTop = 0;
	
	/*
	if (headerHeight > 1024) {
		headerHeight = 1024;
		headerContentTop = 270;
	} else if (headerHeight <= 900) {
		headerContentTop = Math.floor((headerHeight - 360) / 2);
		headerHeight = 900;	
	} else {
		headerContentTop = Math.floor((headerHeight - 360) / 2);
	}
	*/
	
	
	if(headerHeight <= 800) {
		headerHeight = 800;		
	}
	headerContentTop = Math.floor((headerHeight - 360) / 2);	
	if (headerContentTop > 100) headerContentTop  = 100;
		
	
	var bgrTop = 530 - (headerContentTop + 260);
	
	bgrTop = 0;
	
	$('.header').css({'backgroundPosition' : 'center ' + -bgrTop + 'px'});
	
	$('.header').css({'height' : headerHeight});
	
	/*
	var bgLines = bgrTop % 4;
	$('html').css({'backgroundPosition' : 'left' + -bgLines + 'px'});
	*/
	
	$('.headerContent').css({
		'position' : 'absolute',
		'top' : headerContentTop,
		'left' : Math.floor((clientWidth - 983)/2)
	});	
	
	contentTop = $('.header').height() - (headerContentTop + $('.headerContent').height());
	
	$('.content').css({'margin-top': 138 - contentTop});
}
	
function resizeContent() {
	
	var contentHeight = $('.content').height();	
	
	var heightModulo = contentHeight % 100;
	if (heightModulo != 0) {
		contentHeight -= heightModulo;
		contentHeight += 100;
	}	
	
	//layout correction
	contentHeight += 13;

	$('.content').css({'height' : contentHeight});
	
}

function holoprojection() {
	//starts holoprojection (first project selected)
	$('.headerContent .projector').delay(hologramDelay - 500).animate({height: '29px'},500);
	$('.projection > div a').first().delay(hologramDelay).fadeIn(1000, function(){
		$('.projection > div').css({'z-index': 0});																	  
		$(this).parent().css({'z-index': 1000});																	 
		showNext($(this));
	});
}

function showNext(actual) {	
	if (actual.next().size() > 0) {
		//go throught project images
		actual.next().delay(holoItemTime).fadeIn(1000);
		actual.delay(holoItemTime + 1000).fadeOut(1000, function() {
			showNext(actual.next());
		});			
	} else {
		if (actual.parent().next().size() > 0) {
			//go to following project							
			actual.parent().next().children('a').first().delay(3000).fadeIn(1000);
			
			actual.delay(4000).fadeOut(1000, function() {
				$('.projection > div').css({'z-index': 0});																	  
				actual.parent().next().css({'z-index': 1000});			
				
				showNext(actual.parent().next().children('a').first());
			});				
		} else {
			//go back to the first project
			actual.delay(4000).fadeOut(1000);			
			
			holoprojection();
		}
	}
}
/*
function holoprojection() {
	//starts holoprojection (first project selected)
	$('.headerContent .projector').delay(hologramDelay - 500).animate({height: '29px'},500);
	$('.projection > div a').first().delay(hologramDelay).animate({bottom: '-7px'}, 1000, function(){
		$('.projection > div').css({'z-index': 0});																	  
		$(this).parent().css({'z-index': 1000});																	 
		showNext($(this));
	});
}

function showNext(actual) {	
	if (actual.next().size() > 0) {
		//go throught project images
		actual.next().delay(holoItemTime).animate({bottom: '-7px'}, 1000);
		actual.delay(holoItemTime + 1000).animate({bottom: '-292px'}, 1000, function() {
			showNext(actual.next());
		});			
	} else {
		if (actual.parent().next().size() > 0) {
			//go to following project							
			actual.parent().next().children('a').first().delay(3000).animate({bottom: '-7px'}, 1000);
			
			actual.delay(4000).animate({bottom: '-292px'}, 1000, function() {
				$('.projection > div').css({'z-index': 0});																	  
				actual.parent().next().css({'z-index': 1000});			
				
				showNext(actual.parent().next().children('a').first());
			});				
		} else {
			//go back to the first project
			actual.delay(4000).animate({bottom: '-292px'}, 1000);			
			
			holoprojection();
		}
	}
}
*/



function wizardSlider() {
	if ($('.wizard').size() == 0) {
		return;	
	}	
	
	//scroll to wizard
	var scrollHeight = $('.content').get(0).offsetTop + $('.main').get(0).offsetTop - 80;
	$.scrollTo(scrollHeight, wizardScrollSpeed);
	
	var wizMenuLeft = Math.floor((724 - $('.wizardMenu').width()) / 2);
	$('.wizardMenu').css({'left': wizMenuLeft});	
	
	//set up click event handler 
	$('.wizardMenu span').click(function() {									 
		if ($(this).attr('class') != 'active') {
			$('.wizardMenu span').removeClass('active');
			$(this).addClass('active');
			
			var prevItemsCount = $(this).prevAll().size();
	
			var show = $('.slider').children().first();
			
			for (var i = 0; i < prevItemsCount; i++) {
				show = show.next();
			}
			
			show.fadeIn();
			$('.slider').children('.visible').fadeOut().removeClass('visible');
			show.addClass('visible');
		
		}										 
	 	

	});
	
	wizardRotation = setInterval("wizardClickNext()", wizardSpeed);
	
	$('.wizardMenu span').mousedown(function(){
		clearInterval(wizardRotation);												 
	});			
}

function wizardClickNext() {
	if ($('.wizardMenu .active').next().size() == 0) {
		clearInterval(wizardRotation);		
	} else {
		$('.wizardMenu .active').next().click();	
	}	
}
$(function() {
	
		if ($('div.wpcf7-response-output').hasClass('wpcf7-mail-sent-ok')){
			$('input[type=submit]').hide();
			$('label.submit').hide();
			}
		$("form").submit(function() {
			$(".our-loader").css("display","block");
			$('input[type=submit]').attr('disabled', 'disabled');
			$('input[type=submit]').css('color', '#555');
			$('input[type=submit]').css('cursor', 'Default');
			 });
	
});	
	
