var baseurl="http://webfoo.ro/";
var _this_click; 

$(document).ready(function(){
	var pathname = window.location.pathname;
	//#---------------SERVICES-------------------#//
	
	if(pathname.lastIndexOf('services')!=-1){
		
		if(pathname.lastIndexOf('custom_webdesign')!=-1){
			$('ul#menu_services .custom_webdesign').css({'background-position':'1px -367px','width':'224px','margin-left':'-22px'});
			//$.scrollTo('#top',500);
		}
		if(pathname.lastIndexOf('webdesign_packages')!=-1){
			$('ul#menu_services .webdesign_packages').css({'background-position':'2px -918px','width':'224px','margin-left':'-22px'});
			//$.scrollTo('#menu_services',1500);

			$('.request_call_back').click(function(){
				heightt=$(this).parent().height()+200;
				
				$(this).fadeOut();
				if($(this).parent().attr('class')=='pack_big'){
					height_content=$('#wrapper_packages #the_content').height()+200;
					$('#wrapper_packages #the_content').animate({
					height: height_content+'px',	
				  }, 1000 );
				};
				$(this).parent().animate({
					height: heightt+'px',	
				  }, 1000 );
				$(this).next().delay(1000).fadeIn();			
			});
			$('.arrow_awesome .the_image').click(function(){
				heightt=$(this).parent().parent().parent().height()-200;

				$(this).parent().parent().fadeOut('fast');
				$(this).parent().parent().prev().delay(500).fadeIn();
				if($(this).parent().parent().parent().attr('class')=='pack_big'){
					height_content2=$('#wrapper_packages #the_content').height()-200;
					$('#wrapper_packages #the_content').animate({
						height: height_content2+'px',	
					  }, 1000 );
				}
				$(this).parent().parent().parent().animate({
					height: heightt+'px',	
				  }, 1000 );
							
			});
			
			$('input[name=send]').click( function(){
				_this_click = $(this);
			});
			
			var options = {	  
					dataType	: 		'json',
					success		:	showResponseCall,
					async:false,
			}
			$('.request_call').ajaxForm(options);
			
			$(".name_contact").focus(function(){
				if($(this).attr("value") == "Nume*") $(this).attr("value","");
			});
			$(".name_contact").blur(function(){
				if($(this).val() == "") $(this).attr("value", "Nume*");
			}); 	
			$(".email_contact").focus(function(){
				if($(this).attr("value") == "E-mail*") $(this).attr("value","");
				if($(this).attr("value")=="The E-mail field must contain a valid email address.") $(this).attr("value","");
			});
			$(".email_contact").blur(function(){
				if($(this).val() == "") $(this).attr("value", "E-mail*");
			});
			$(".phone_contact").focus(function(){
				if($(this).attr("value") == "Telefon*") $(this).attr("value","");
			});
			$(".phone_contact").blur(function(){
				if($(this).val() == "") $(this).attr("value", "Telefon*");
			});  		
			$(".company").focus(function(){
				if($(this).attr("value") == "Companie") $(this).attr("value","");
			});
			$(".company").blur(function(){
				if($(this).val() == "") $(this).attr("value", "Companie");
			});  	
			$('input[type="text"]').focusin(function(){
				$(this).attr("value","");
				$(this).css({"color":"#868686","font-size":"16px","background":"url("+baseurl+"assets/images/bg_input_request_call.png) no-repeat 0 0"});
			});			
		}
		if(pathname.lastIndexOf('design_identity')!=-1){
			$('ul#menu_services .design_identity').css({'background-position':'2px -1469px','width':'224px','margin-left':'-22px'});
			$.scrollTo('#menu_services',1500);
		}
		
		if(pathname.lastIndexOf('online_strategy')!=-1){
			$('ul#menu_services .online_strategy').css({'background-position':'2px -2020px','width':'224px','margin-left':'-22px'});
			$.scrollTo('#menu_services',1500);
			$('#menu_s li .case2').css('display','none');
			$('#menu_s li .case1').css('margin-left','50px');
		}
		if(pathname.lastIndexOf('online_marketing')!=-1){
			$('ul#menu_services .online_marketing').css({'background-position':'2px -2571px','width':'224px','margin-left':'-22px'});
			$.scrollTo('#menu_services',1500);
			$('#menu_s li .case2').css('display','none');
			$('#menu_s li .case1').css('margin-left','50px');
		}
	

		$('.top_arrow').click(function(){
			$.scrollTo('#header',500);
		});
		
		$('ul#menu li.services a').addClass('selected');
		$('ul#menu li.services a').hover(
			function() { 
				$(this).removeClass('selected');
			},
			function() { 
				$(this).addClass('selected');
			}
		);
		$('#menu_s li .process_ex').css('background-position','-218px -80px');
		//ajax loader 
		$('#menu_s li a.case1,#menu_s li a.case2,#menu_s li a.process_ex,#menu_s li a.expertise_of,#menu_s li a.free_quote').click(function(){
			
			$('#menu_s li .case1').css('background-position','0 0');
			$('#menu_s li .case2').css('background-position','-111px 0 ');
			$('#menu_s li .process_ex').css('background-position','-218px 0 ');
			$('#menu_s li .expertise_of').css('background-position','-400px 0');
			$('#menu_s li .free_quote').css('background-position','-547px 0');
		

			
			var clasa=$(this).attr('class');

			switch (clasa){
				case 'case1':
					$('#menu_s li .'+clasa).css('background-position','0 -80px');
					
				break;
				case 'case2':
					$('#menu_s li .'+clasa).css('background-position','-111px -80px');
				
				break;
				case 'process_ex':
					$('#menu_s li .'+clasa).css('background-position','-218px -80px');
					
				break;
				case 'expertise_of':
					$('#menu_s li .'+clasa).css('background-position','-400px -80px');
					
				break;
				case 'free_quote':
					$('#menu_s li .'+clasa).css('background-position','-547px -80px');
					
				break;
			
			}

					
		//	$('#menu_s li .case1').css('background-position',' 0 -40px');
		//	$('#menu_s li .case2').css('background-position','-111px -40px');
		//	$('#menu_s li .process_ex').css('background-position','-218px -40px');
		//	$('#menu_s li .expertise_of').css('background-position','-400px -40px');
		//	$('#menu_s li .free_quote').css('background-position','-547px -40px');				
			
			$.scrollTo('#top',500);
			$('script[src*='+baseurl+'assets/client/fileuploader.js]').remove();

			var link = 	$(this).attr('href');
			var toLoad;
			toLoads=$.ajax({
					url: link,
					async: false,

			}).responseText;

		
			var zsl = $(toLoads).children('#ajax_container').children().attr('id');
			toLoad = link + ' #' + zsl;
			$('#ajax_container').fadeOut('fast',loadContent);

			$('#load').fadeIn('fast');

			function loadContent() {

				$('#ajax_container').load(toLoad,'',showNewContent());

			}
			function showNewContent() {

				$('#ajax_container').fadeIn('slow').ajaxComplete(function() {

					$('script[src*='+baseurl+'assets/client/fileuploader.js]').remove();
					Cufon.refresh();
					hideLoader();
					//## services QUOTE//
					quote=link.lastIndexOf("quote");	
					
					if(quote!=-1) {
						createFormQuote();
						link="";
					}
					//## end services QUOTE//
				});
			}
			function hideLoader() {
				$('#load').fadeOut('normal');
			}
			return false;	
		});
		//end ajax loader	
	}
	
	/* quote simple */
	if(pathname.lastIndexOf("quote")!=-1){
		createFormQuote();
		$.scrollTo('#top',500);
	}
	/*quote simple */
	//#---------------PORTFOLIO-------------------#//	
	if(pathname.lastIndexOf('portfolio')!=-1){
		$('#portfolio_menu').css({'float':'left','margin-top':'50px'});
		$('ul#menu li.portofolio a').addClass('selected');
		$('ul#menu li.portofolio a').hover(
			function() { 
				$(this).removeClass('selected');
			},
			function() { 
				$(this).addClass('selected');
			}
		); 
		
		$('.image_port >a').hover(
			function() { 
				$(this).stop().animate({"opacity": 0.3}); 
				$(this).parent().children('.magnifier').show();
			},
			function() { 
				$(this).stop().animate({"opacity": 1}); 
				$(this).parent().children('.magnifier').hide();
			}
		);
	}
	//#---------------TEAM-------------------#//		
	if(pathname.lastIndexOf('team')!=-1){
		$('ul#menu li.team a').addClass('selected');
		$('ul#menu li.team a').hover(
			function() { 
				$(this).removeClass('selected');
			},
			function() { 
				$(this).addClass('selected');
			}
		);
		//# TEAM cool guy #//
			var optionsQ = {  
				dataType	: 		'json',
				success		:	showResponseCool,
			}
			$('.questioning').ajaxForm(optionsQ);
		//});


		var $li = $(".quotess").hide();
		var len = $li.length;
		
		$('input[name=send]').live('click', function(){
			var counter = 1; // how many items to display
			var randomnumber;
			while (counter > 0) {
				randomnumber = Math.floor(Math.random() * (len + 1));
				if ($li.eq(randomnumber).is(":hidden")) {
					//$('textarea').val('');
					$('#tooltip_cool2').delay(1000).fadeIn();
					$('#tooltip_cool').fadeOut();
					$li.eq(randomnumber).fadeIn();	
				}
				counter -= 1;
			}
		});	

		$('.ask_another').click(function(){
			$li.each(function() { $(this).hide();});
			$('#tooltip_cool').delay(1000).fadeIn();
			$('#tooltip_cool2').fadeOut();		
		});
		
		$('#tooltip_cool textarea').focusin(function(){				
		//	$('#tooltip_cool label').css({'background-position':'center bottom','color':'#262626'});
			$('#tooltip_cool label').css('background-position','center bottom');
		}); 
		$('#tooltip_cool textarea').focusout(function(){
			$('#tooltip_cool label').css('background-position','center top');
		}); 
		//# end TEAM cool guy//
	}
	//#---------------RESEARCH------------------#//
		if(pathname.lastIndexOf('research')!=-1){
			$('ul#menu li.research a').addClass('selected');
			$('ul#menu li.research a').hover(
				function() { 
					$(this).removeClass('selected');
				},
				function() { 
					$(this).addClass('selected');
				});
			var options = {  
				dataType	: 		'json',
				success		:		showResponseApp,
			}
			$('.research_app').ajaxForm(options);
			
			
			createUploader();	
			
			$('#bg_wide #services_slider_top').css('margin-top','76px')
			$('#bg_wide #services_slider_top p,#bg_wide #services_slider_top h1').css({'float':'none','width':'auto','padding-right': '20px','margin-left':'0'});			
			$('#bg_wide #services_slider_top p').css('line-height','16px');
		   
			$("#upload_stuff").bind('change', function() {
				$( "input[name*=fila]").val($('.qq-upload-file').text());
			});
			

			
		}
	
		
	//#---------------CONTACT-------------------#//	
	if(pathname.lastIndexOf('contact')!=-1){
	
		$("#name_contact").focus(function(){
			if($(this).attr("value") == "Nume*") $(this).attr("value","");
		});
		$("#name_contact").blur(function(){
			if($(this).val() == "") $(this).attr("value", "Nume*");
		}); 	
		$("#email_contact").focus(function(){
			if($(this).attr("value") == "E-mail*") $(this).attr("value","");
		});
		$("#email_contact").blur(function(){
			if($(this).val() == "") $(this).attr("value", "E-mail*");
		});
		$("#phone_contact").focus(function(){
			if($(this).attr("value") == "Telefon") $(this).attr("value","");
		});
		$("#phone_contact").blur(function(){
			if($(this).val() == "") $(this).attr("value", "Telefon");
		});  	
		$("#message_contact").focus(function(){
			if($(this).attr("value") == "Introduceti mesajul") $(this).attr("value","");	
		});
		$("#message_contact").blur(function(){
			if($(this).val() == "") $(this).attr("value", "Introduceti mesajul");
		});  
		 

		$('input[type="text"]').focusin(function(){
			if($(this).attr("value") == "Camp obligatoriu"){
				$(this).attr("value","");
				$(this).css({"color":"#0099D9","background":"url("+baseurl+"assets/images/bg_input_contact.png) no-repeat 0 0"});
			}		
		});
		 var options = {  
			dataType	: 		'json',
			success		:	showResponseContact,
		}
		$('.contact_form_submit').ajaxForm(options);
	}
	//#---------------imprint-------------------#//	
	if(pathname.lastIndexOf('imprint')!=-1){

		$('#bg_wide #services_slider_top').css('margin-top','133px')
	//	$('#bg_wide #services_slider_top p,#bg_wide #services_slider_top h1').css({'float':'none','width':'auto','padding-right': '20px','margin-left':'0'});			
	}
	if(pathname.lastIndexOf('terms')!=-1){

		$('#bg_wide #services_slider_top').css('margin-top','76px')
		//$('#bg_wide #services_slider_top p,#bg_wide #services_slider_top h1').css({'float':'none','width':'auto','padding-right': '20px','margin-left':'0'});			
	}
	//##HOME//
	//slider sus			
	$('#slider-code').tinycarousel();

	//hover submeniu
	$('#sub_menu li').hover
	(
		function() { 
			$(this).stop().animate({"opacity": 1}); 
		},
		function() { 
			$(this).stop().animate({"opacity": 0.5}); 
		}
	);
	//hover custom packages

	$('#sub_header .white_overlay').hover
	(
		function() { 
			$(this).stop().animate({opacity: 1}); 
		},
		function() { 
			$(this).stop().animate({opacity: 0.7}); 
		}
	);

	//hover process

	$('#sub_header #learn_process a').hover
	(
		function() { 
			$('#sub_header #learn_process .arrow').stop().animate({'margin-left' : '40px'}); 
		},
		function() { 
			$('#sub_header #learn_process .arrow').stop().animate({'margin-left' : '20px'}); 
		}
	);

	//slider main
	$('#slider_main').tinycarousel({ pager: true, 
	//interval: true  
	});	
	$('#slider_footer').tinycarousel({rewind: true,controls: true});
	$('#services_slider_top').tinycarousel();
	
	$(".jQTooltip").simpletooltip();
	//## end HOME//
	
	//# FORM QUOTE//
	function createFormQuote(){
		$('#menu_s li .process_ex').css('background-position','-218px 0');
		$('#menu_s li .free_quote').css('background-position','-547px -80px');
		$('input[type="text"]').focusin(function(){

			$(this).prev().css('background-position','center -51px');					
			$(this).css('color','#252525');
			if($(this).attr("value") == "Camp obligatoriu"){
				$(this).attr("value","");
				$(this).css({"color":"#868686","background":"url("+baseurl+"assets/images/bg_input_quote.png) no-repeat 0 0"});
			}
			
		});
		
		$('input[type="text"]').focusout(function(){
			if($(this).attr("value") != "")
			{
				$(this).css("color","#868686");
			}
			$('label').css('background-position','center top');
		}); 
		$('#wrapper_quote textarea').focusin(function(){				
			$(this).prev().css('background-position','center -51px');	
			$(this).css('color','#252525');
		}); 
		$('#wrapper_quote textarea').focusout(function(){
			if($(this).attr("value") != "")
			{
				$(this).css("color","#868686");
				$(this).prev().css('background-position','center -51px')
			}
			$('label').css('background-position','center top');
		}); 
					
		var options = {  
				dataType	: 		'json',
				success		:	showResponseFreeQuote
			}
		$('.public_form').ajaxForm(options);
		
		$( "#slider_importance" ).slider({
				min: -100,
				max: 100,
				value: 0,
				slide: function( event, ui ) {
					$( "input[name*=amount]" ).val( ui.value );
					if(ui.value >=0){
						$('#wrapper_quote #quality_importance').css('opacity',(ui.value/100) );
						$('#wrapper_quote #price_importance').css('opacity',0);
						}
					if(ui.value<=0){
						$('#wrapper_quote #price_importance').css('opacity',-(ui.value/100));
						$('#wrapper_quote #quality_importance').css('opacity',0 );
						}
				}
		});
		$( "input[name*=amount]" ).val( $( "#slider_importance" ).slider( "value" ) );
	
		$("#project_start").selectbox();

		loadScript(baseurl+'assets/client/fileuploader.js', function() {
			createUploader();
		});  
		
		$("#upload_stuff").bind('change', function() {
			$( "input[name*=fila]").val($('.qq-upload-file').text());
		});

		$('#QapTcha').remove();
		$('#robot-you').append('<div id="QapTcha"></div>');
		$('#QapTcha').QapTcha();
		
	}
	function showResponseContact(data) {	
		if(data.message.lastIndexOf("Name")!=-1) $( "input[name=name]").css({'background':'url('+baseurl+'assets/images/error_contact_form.png) no-repeat 0 0','color':'#fff'}).val('Camp obligatoriu');
		if(data.message.lastIndexOf("E-mail")!=-1) $( "input[name=email]").css({'background':'url('+baseurl+'assets/images/error_contact_form.png) no-repeat 0 0','color':'#fff'}).val('Camp obligatoriu');
		//if(data.message.lastIndexOf("Your wisdom")!=-1) $( "input[name=wisdom]").css({'background':'url('+baseurl+'assets/images/error_wisdom.png) no-repeat 0 0','color':'#fff'}).val('Camp obligatoriu');
		if(data.message=='Message sent!'){
			$('input[type="text"]').val('');
			$('.contact_form_submit textarea').val('');
			$('.contact_form_submit').fadeOut();
			$('#contact_thanks').delay(1000).fadeIn();
		}
	}	
	function showResponseCall(data) {
		var _p = _this_click.parent();
		
		if(data.message=="Message sent!"){
			// fade in, fade out
			_p.fadeOut().delay(1000);
			_p.parent().children(".succes_formu").delay(1000).html(data.message).fadeIn();		
		}
	
		_p.parent().children(".errors_request").html(data.message);

		if(data.message.lastIndexOf("Name")!=-1) {

			_p.find("input[name=name]").css({'background':'url('+baseurl+'assets/images/bg_input_error2.png) no-repeat 0 0','font-size':'11px','color':'#fff'}).val($(".errors_request > p:contains('Name')").text());
		}
		if(data.message.lastIndexOf("E-mail")!=-1){
	
			_p.find("input[name=email]").css({'background':'url('+baseurl+'assets/images/bg_input_error2.png) no-repeat 0 0','font-size':'11px','color':'#fff'}).val($(".errors_request > p:contains('E-mail')").text());
			
		}
		if(data.message.lastIndexOf("Phone")!=-1) {
			_p.find( "input[name=phone]").css({'background':'url('+baseurl+'assets/images/bg_input_error2.png) no-repeat 0 0','font-size':'11px','color':'#fff'}).val($(".errors_request > p:contains('Phone')").text());
		}

		_this_click = NULL;
	}	
	function showResponseFreeQuote(data) {
		if(data.message.lastIndexOf("Name")!=-1) $( "input[name=name]").css({'background':'url('+baseurl+'assets/images/bg_input_error.png) no-repeat 0 0','color':'#fff'}).val('Camp obligatoriu');
		if(data.message.lastIndexOf("E-mail")!=-1) $( "input[name=email]").css({'background':'url('+baseurl+'assets/images/bg_input_error.png) no-repeat 0 0','color':'#fff'}).val('Camp obligatoriu');
		if(data.message.lastIndexOf("Phone")!=-1) $( "input[name=phone]").css({'background':'url('+baseurl+'assets/images/bg_input_error.png) no-repeat 0 0','color':'#fff'}).val('Camp obligatoriu');
		if(data.message=='Message sent!'){
				//alert(data.message);
				
				$('input[type="text"]').val('');
				$('#wrapper_quote textarea').text('');
				$('#forms').fadeOut();
				$('#thank_u_quote').delay(1000).fadeIn();
			}
	}	

	
	function showResponseApp(data) {
		if(data.message=='Application sent!'){
			alert(data.message);
			location.reload();
		}
		else alert(data.message);
	}
	function showResponseCool(data) {
		$('textarea').val('');
	}
});
function loadScript(url, callback){

    var script = document.createElement("script")
    script.type = "text/javascript";

    if (script.readyState){  //IE
        script.onreadystatechange = function(){
            if (script.readyState == "loaded" ||
                    script.readyState == "complete"){
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //Others
        script.onload = function(){
            callback();
        };
    }

    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}
//var baseurl="http://webfoo-london.co.uk/";
function createUploader(){            
	var uploader = new qq.FileUploader({
		element: document.getElementById('file-uploader'),
		action:baseurl+'assets/server/php.php',
		debug: true,
		multiple:false,
	});           
}
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";

	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
	for(var item in arr) {
	var value = arr[item];

	if(typeof(value) == 'object') { //If it is an array,
	dumped_text += level_padding + "'" + item + "' ...\n";
	dumped_text += dump(value,level+1);
	} else {
	dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
	}
	}
	} else { //Stings/Chars/Numbers etc.
	dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}
Cufon.replace('#menu li a', {fontFamily:'Teletype', hover: true});
Cufon.replace('#wrapper_quote h1,#wrapper_quote #importance h3,#wrapper_quote .price_importance,#wrapper_quote .quality_importance,#wrapper_quote #price_importance,#wrapper_quote #quality_importance,#wrapper_quote h4,#wrapper_quote #right .title,#wrapper_quote #right .subtitle',{fontFamily: 'Museo 300'} );
Cufon.replace('.country_phone, #slider li, #webfoo h2, #slider span,#main #left h2,#bg_wide h1,#header .quotess, #bg_wide span,#header #contact_officer,#wrapper_packages  li.titel',{fontFamily: 'Museo 500'} );
Cufon.replace('#sub_menu a,#custom h1, #packeges h1,#footer #left h1, #footer #center h1,#footer #right h2, #footer #right h1,#footer ul li a, #footer #center h2 a,#custom a, #packeges a,#testimonials .satisfaction1, #testimonials .satisfaction2, #wrapper_expertise .title, #wrapper_expertise .subtitle,  #wrapper_expertise_design .title,#wrapper_expertise_design .subtitle, #wrapper_marketing_expertise .title,#wrapper_marketing_expertise .subtitle,',{fontFamily: 'Museo 300'} );
Cufon.replace('#desc_serv h1,#desc_serv h2',{fontFamily: 'Museo 300', hover: true} );
Cufon.replace('#main #left h1,#testimonials h1,#testimonials h2,#wrapper_packages .price_holder span',{fontFamily: 'Museo 700'} );
Cufon.replace('#wrapper_process .title, #wrapper_process .subtitle,#wrapper_process_design .title,#wrapper_process_design .subtitle,#wrapper_process #center .do_it, #wrapper_process #center .contact_us,#wrapper_process_design #right .do_it, #wrapper_process_design #right .contact_us',{fontFamily: 'Futura Bk BT'});
Cufon.replace('#wrapper_marketing_process .title,#wrapper_marketing_process .subtitle,#wrapper_marketing_process #center .do_it, #wrapper_marketing_process #center .contact_us,',{fontFamily: 'Futura Bk BT'});
Cufon.replace('#wrapper_strategy_process .title,#wrapper_strategy_process .subtitle,#wrapper_strategy_process #center .do_it, #wrapper_strategy_process #center .contact_us,',{fontFamily: 'Futura Bk BT'});
Cufon.replace('#wrapper_strategy_expertise .title,#wrapper_strategy_expertise .subtitle,#middle_text .title',{fontFamily: 'Futura Bk BT'});
Cufon.replace('#main_research .left .title,#main_research .left .subtitle,#main_research .right .title,#main_research .right .subtitle,#wisdom_thanks,#contact_thanks, .succes_formu',{fontFamily: 'Museo 300'} );

Cufon.replace('.post_title',{fontFamily: 'Museo 100'} );
Cufon.replace('.country_address, .country_city, .country_title, #learn_process #middle a,#header h4,#wide_portfolio h1,.desc_team,.name_team,#the_team h3,#juniors h4,#header .ask_another,#wide_main_terms h1,#main_approach .left .title,#main_approach .left .subtitle,#main_approach .right .title,#main_approach .right .subtitle,.add_this_buton',{fontFamily: 'Museo 300'} );

//Cufon.replace('#wrapper_process #center',{fontFamily: 'Futura LT'} );
