jQuery(document).ready(function(){

	jQuery(window).resize(function() {
		hideSize();
		$('#float-forms').center();
	});

	/**
	 * fixed nav
	 */
	
	
	var doc = jQuery(this);
	var nav = jQuery('#nav');
	var navFx = nav.find('.nav.fx').css({display:'block',opacity:0});
	var navTop = nav.offset().top;
	
	var step = 200; // in pixels - this means that in 100 pixels, fx's opacity will change from 0 to 1 
	
	jQuery(document).scroll(function(e) {
		if(doc.scrollTop() >= navTop) {
			nav.css({position:'fixed',top:0});
			if(doc.scrollTop() - navTop <= step) {
				alpha = (doc.scrollTop() - navTop) / step;
				navFx.css({opacity:alpha});
			} else {
				navFx.css({opacity:1});
			}
		} else {
			nav.css({position:'absolute',top:navTop});
			nav.find('.nav.fx').css({opacity:0});
		}
	});
	// navigation background FX
	
	
	//side center
	$('#float-forms').center();
	
	
	/**
	 * equal height home_boxes
	 */
	var boxes = jQuery('#home_boxes .box_content');
	var bHeight = 0;
	
	boxes.each(function(n){
		if(jQuery(this).height() > bHeight) bHeight = jQuery(this).height();
	});
	if(bHeight > 0) {
		boxes.css({height:bHeight});
	}
	
	//portfolio slider
	$index=0;
	jQuery('a.next').click(function(){
		jQuery('a.prev').removeClass('disabled');
		if(jQuery(this).hasClass('disabled')!=true){
			$index += 3;
			if( $index==jQuery('#midportfofio li').size()-3 ){
				jQuery(this).addClass('disabled');
			}
			jQuery('div.items_wrapper').scrollTo('+=933px', 700 );
		}
	});
	jQuery('a.prev').click(function(){
		jQuery('a.next').removeClass('disabled');
		if(jQuery(this).hasClass('disabled')!=true){
			$index -= 3;
			if( $index==0 ){
				jQuery(this).addClass('disabled');
			}
			jQuery('div.items_wrapper').scrollTo('-=933px', 700);
		}
	});
	
	//footer form
	jQuery('#ftct_name').defaultvalue("Numele tau");
	jQuery('#ftct_email').defaultvalue("emailul-tau@domeniu.com");
	jQuery('#ftct_phone').defaultvalue("0744 444 444");
	jQuery('#ftct_message').defaultvalue("Buna ziua!" + '\n\n' + "As dori o cotatie pentru un proiect de web design...");
	
	//side form
	jQuery('#contact-float-name').defaultvalue("Numele tau");
	jQuery('#contact-float-email').defaultvalue("emailul-tau@domeniu.com");
	jQuery('#contact-float-phone').defaultvalue("0744 444 444");
	jQuery('#contact-float-message').defaultvalue("Buna ziua!" + '\n\n' + "As dori o cotatie pentru un proiect de web design...");
	
	//nl field
	jQuery('#nl_email').defaultvalue("adresa-ta@domeniu.com");
	
	//3D carousel
	jQuery("#carousel").CloudCarousel({			
		xPos: 235,
		yPos: 25,
		xRadius: 100, //204
		yRadius: 1, //47
		//FPS: 50,
		//bringToFront: true,
		//autoRotate: 'right',
		//autoRotateDelay: 2000,
		buttonLeft: jQuery("#left-but"),
		buttonRight: jQuery("#right-but")
	});
	
	//carousel on homepage
	//jQuery("#carousel").css('padding','0').css('height','280px');
	jQuery('img.cloudcarousel').click(function(){
		location.href = jQuery(this).attr('href');
	});
	
	//lighbox
	jQuery('.lightbox').lightbox();
	
	//side forms
	$('a#search-float-but, a#contact-float-but').toggle(
		function(){
		   $(this).parent().animate({right: '0',})
		},
		function(){
		   $(this).parent().animate({right: '-350',})
		}
	);
});


jQuery.fn.center = function () {
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() - 100 + "px");
    return this;
}

function hideSize() {
	if(jQuery(window).width() <= 1160){
		jQuery('#float-forms').hide();
	}else{
		jQuery('#float-forms').show();
	}
}
	

var multipleValues = new Array();
multipleValues[0] = "500 - 1000 Eur";
multipleValues[1] = "1000 - 1500 Eur";
multipleValues[2] = "1500 - 2500 Eur";
multipleValues[3] = "2500 - 5000 Eur";
multipleValues[4] = "5000 - 10000 Eur";
multipleValues[5] = "10000 - 50000 Eur";
multipleValues[6] = "Peste 50000 Eur";

function newsletter() {
	if(jQuery('#nl_email').val()!=""){
		email=jQuery('#nl_email').val();
		jQuery.ajax({
			url: 'http://www.prologue.ro/wp-content/themes/prologue/ajax/newsletter.php',
			type: 'GET',
			cache: false,
			dataType: 'html',
			data: 'email='+email,
			success: function(responseText){
				vals = responseText.split("___");
				if(vals[0]==0){
					jQuery('#nl_email').css('border','1px solid #f00');
				}else{
					jQuery('#nl_email').css('border','none');
				}
				jQuery('#nl_email').val(vals[1]);
			}
		});
	}
}

function contact_form() {
	name=jQuery('#ftct_name').val();
	email=jQuery('#ftct_email').val();
	phone=jQuery('#ftct_phone').val();
	message=jQuery('#ftct_message').val();
	
	jQuery('#ftct_email').css('border','none');
	jQuery('#ftct_name').css('border','none');
	jQuery('#ftct_phone').css('border','none');
	jQuery('#ftct_message').css('border','none');
	
	if(name!="" && email!="" && phone!="" && message!=""){
		jQuery.ajax({
			url: 'http://www.prologue.ro/wp-content/themes/prologue/ajax/contact.php',
			type: 'POST',
			cache: false,
			dataType: 'html',
			data: 'email='+email+'&name='+name+'&phone='+phone+'&message='+message,
			success: function(responseText){
				vals = responseText.split("___");
				if(vals[0]==0){
					if(strpos(vals[1], 'Email')!=false){
						jQuery('#ftct_email').css('border','1px solid #f00');
						jQuery('#ftct_email').val(vals[1]);
					}
					if(strpos(vals[1], 'Nume')!=false){
						jQuery('#ftct_name').css('border','1px solid #f00');
						jQuery('#ftct_name').val(vals[1]);
					}
					if(strpos(vals[1], 'numar')!=false){
						jQuery('#ftct_phone').css('border','1px solid #f00');
						jQuery('#ftct_phone').val(vals[1]);
					}
					if(strpos(vals[1], 'mesaj')!=false){
						jQuery('#ftct_message').css('border','1px solid #f00');
						jQuery('#ftct_message').val(vals[1]);
					}
				}else{
					jQuery('#ftct_email').css('border','none');
					jQuery('#ftct_name').css('border','none');
					jQuery('#ftct_phone').css('border','none');
					jQuery('#ftct_message').css('border','none');
				
					jQuery('#ftct_name').defaultvalue("Numele tau");
					jQuery('#ftct_email').defaultvalue("emailul-tau@domeniu.com");
					jQuery('#ftct_phone').defaultvalue("0744 444 444");
					jQuery('#ftct_message').defaultvalue("Buna ziua!" + '\n\n' + "As dori o cotatie pentru un proiect de web design...");
					
					jQuery('#msgSucces').html(vals[1]);
					
					_gaq.push(['_trackPageview', 'footer-contact/']);
				}
			}
		});
	}else{
		alert("Te rugam sa completezi toate campurile corect!");
	}
}

function contact_side_form() {
	name=jQuery('#contact-float-name').val();
	email=jQuery('#contact-float-email').val();
	phone=jQuery('#contact-float-phone').val();
	message=jQuery('#contact-float-message').val();
	
	jQuery('#contact-float-email').css('border','none');
	jQuery('#contact-float-name').css('border','none');
	jQuery('#contact-float-phone').css('border','none');
	jQuery('#contact-float-message').css('border','none');
	
	if(name!="" && email!="" && phone!="" && message!=""){
		jQuery.ajax({
			url: 'http://www.prologue.ro/wp-content/themes/prologue/ajax/contact.php',
			type: 'POST',
			cache: false,
			dataType: 'html',
			data: 'side=1&email='+email+'&name='+name+'&phone='+phone+'&message='+message,
			success: function(responseText){
				vals = responseText.split("___");
				if(vals[0]==0){
					if(strpos(vals[1], 'Email')!=false){
						jQuery('#contact-float-email').css('border','1px solid #f00');
						jQuery('#contact-float-email').val(vals[1]);
					}
					if(strpos(vals[1], 'Nume')!=false){
						jQuery('#contact-float-name').css('border','1px solid #f00');
						jQuery('#contact-float-name').val(vals[1]);
					}
					if(strpos(vals[1], 'numar')!=false){
						jQuery('#contact-float-phone').css('border','1px solid #f00');
						jQuery('#contact-float-phone').val(vals[1]);
					}
					if(strpos(vals[1], 'mesaj')!=false){
						jQuery('#contact-float-message').css('border','1px solid #f00');
						jQuery('#contact-float-message').val(vals[1]);
					}
				}else{
					jQuery('#contact-float-email').css('border','none');
					jQuery('#contact-float-name').css('border','none');
					jQuery('#contact-float-phone').css('border','none');
					jQuery('#contact-float-message').css('border','none');
				
					jQuery('#contact-float-name').defaultvalue("Numele tau");
					jQuery('#contact-float-email').defaultvalue("emailul-tau@domeniu.com");
					jQuery('#contact-float-phone').defaultvalue("0744 444 444");
					jQuery('#contact-float-message').defaultvalue("Buna ziua!" + '\n\n' + "As dori o cotatie pentru un proiect de web design...");
					
					jQuery('#msgSideSucces').html(vals[1]).show();
					
					_gaq.push(['_trackPageview', 'side-contact/']);
				}
			}
		});
	}else{
		alert("Te rugam sa completezi toate campurile corect!");
	}
}

function strpos (haystack, needle, offset) {
    var i = (haystack + '').indexOf(needle, (offset || 0));
    return i === -1 ? false : true;
}

function change_proiect(id) {
	 for(i=1;i<=9;i++) {
		 jQuery("#tr"+i).hide();
	 }
	 restoreOpt();
	 if(id=="1" || id=="1-1" || id=="1-2" || id=="1-3" || id=="1-4" || id=="1-5") {
		 for(i=1;i<=5;i++) {
			 jQuery('#tr'+i).show();
		 }
		 jQuery('#tr8').show();
		 if(id=="1-2"){
			 removeOpt("500 - 1000 Eur");
		 }
		 if(id=="1-3"){
			 removeOpt("500 - 1000 Eur");
			 removeOpt("1000 - 1500 Eur");
		 }
	 }
	 if(id=="2") {
		 for(i=7;i<=8;i++) {
			 jQuery('#tr'+i).show();
		 }
		 jQuery('#tr1').show();
		 jQuery('#tr5').show();
	 }
	 if(id=="3" || id=="3-1" || id=="3-2" || id=="3-3" || id=="3-4" || id=="3-5" || id=="3-6" || id=="5") {
		 for(i=8;i<=9;i++) {
			 jQuery('#tr'+i).show();
		 }
		 jQuery('#tr1').show();
		 if(id=="3-2" || id=="3-6"){
			 removeOpt("500 - 1000 Eur");
			 removeOpt("1000 - 1500 Eur");
			 removeOpt("1500 - 2500 Eur");
		 }
		 if(id=="3-1" || id=="3-3" || id=="3-4"){
			 removeOpt("500 - 1000 Eur");
			 removeOpt("1000 - 1500 Eur");
			 removeOpt("1500 - 2500 Eur");
			 removeOpt("2500 - 5000 Eur");
		 }
		 if(id=="3-5"){
			 removeOpt("500 - 1000 Eur");
			 removeOpt("1000 - 1500 Eur");
			 removeOpt("1500 - 2500 Eur");
			 removeOpt("2500 - 5000 Eur");
			 removeOpt("5000 - 10000 Eur");
		 }
		 if(id=="8-3"){
		 	 removeOpt("500 - 1000 Eur");
		 }
	 }
	 if(id=="4") {
		 jQuery('#tr1').show();
		 jQuery('#tr5').show();
		 jQuery('#tr6').show();
	 }
	 if(id=="6" || id=="7" || id=="8" || id=="8-1" || id=="8-2" || id=="8-3" || id=="8-4") {
		 jQuery('#tr1').show();
		 jQuery('#tr8').show();
		 jQuery('#tr10').show();
	 }
}

function removeOpt(vals){
	jQuery('#buget').find('option').each(function(i, option){
		if(vals == jQuery(option).val()){
			jQuery(option).remove();
		}
	});
}

function restoreOpt(){
	jQuery('#buget').find('option').each(function(i, option){
		jQuery(option).remove();
	});
	jQuery.each(multipleValues, function(key, value){
		jQuery('#buget').append(jQuery("<option></option>").attr("value", value).text(value));
	});
}


//default value for forms - plugin
(function($) {
	$.fn.defaultvalue = function() {
		// Scope
		var elements = this;
		var args = arguments;
		var c = 0;
		
		return(
			elements.each(function() {				
				
				// Default values within scope
				var el = $(this);
				var def = args[c++];

				el.val(def).focus(function() {
					if(el.val() == def) {
						el.val("");
					}
					el.blur(function() {
						if(el.val() == "") {
							el.val(def);
						}
					});
				});
				
			})
		);
	}
})(jQuery);


/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(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);
