/* <![CDATA[ */

$(document).ready(function(){

	jQuery.fn.MailTo = function() {
		return this.each(function(){
			var mailtoText = $(this).text();
			mailtoText = mailtoText.replace("[at]","@");
			mailtoText = mailtoText.replace("[dot]",".");
			mailtoText = mailtoText.replace("[dot]",".");
			$(this).html("<a href=\"mailto:"+mailtoText+"\">"+mailtoText+"</a>");
		});
	};
	$(".elink").MailTo();
	
	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});
	
	function carousel_initcallback(carousel){
		$('.jcarousel-list').live('mouseover mouseout',function(event) {       
			event.preventDefault();
			if (event.type == 'mouseover') {
				carousel.stopAuto();
			};
			if (event.type == 'mouseout') {
				carousel.startAuto()
			}; 
		});		
	}	
	
	function carousel_itemvisibleincallback(carousel, item, i, state, evt){
		$(".modal").fancybox({titleShow:false,scrolling:'no',padding:0,centerOnScroll:true,overlayColor:'#523f95',overlayOpacity:0.8,showCloseButton:true});
		Cufon.replace('#projects .jcarousel-list li .carousel-quote .carousel-quote-cell p',{fontFamily:'Futura Std'});	
		$('#projects .jcarousel-list li .carousel-quote .carousel-quote-cell p').css("display","block");			
	}	
	
	if ($('#carousel .jcarousel-list').children().size() > 1) {
		$('#carousel').jcarousel({
			scroll:1,
			auto:10,
			wrap:'circular',
			easing:'easeInOutCubic',
			animation:800,
			buttonNextHTML:'<div>></div>',
			buttonPrevHTML:'<div><</div>',	
			initCallback: carousel_initcallback,
			itemVisibleInCallback: {onBeforeAnimation: carousel_itemvisibleincallback}
		});	
	}	
	
	if ($('#projects .jcarousel-list').children().size() > 1) {
		$('#projects').jcarousel({
			scroll:1,
			auto:10,
			wrap:'both',
			easing:'easeInOutCubic',
			animation:800,
			buttonNextHTML:'<div>></div>',
			buttonPrevHTML:'<div><</div>',	
			initCallback: carousel_initcallback,
			itemVisibleInCallback: {onBeforeAnimation: carousel_itemvisibleincallback}
		});	
	}	
	
	$('.modal').append(function() {
		var href = $(this).attr('href');
		var append = '';
		if (href.indexOf( "/wp-content/uploads/") == -1) {
			append = 'modal/true/';
		}
		$(this).attr('href',href+append)
	});		
		
	$(".modal").fancybox({
		titleShow:false,
		scrolling:'no',
		padding:0,
		centerOnScroll:true,
		overlayColor:'#523f95',
		overlayOpacity:0.8,
		showCloseButton:true
	});		
	
	$('#form_footer_links_for_clients').submit(function () { 
		var selected_value = $('#form_footer_links_for_clients #service option:selected').val();
		top.location.href = selected_value;
		return false;
	})
	
	$('.acc_container').hide();
	$('.acc_trigger').click(function(){
		if( $(this).next().is(':hidden') ) {
			$('.acc_trigger').removeClass('active').next().slideUp();
			$(this).toggleClass('active').next().slideDown();
		}
		return false;
	});	
	
	$('#action_button_newsletter_subscribe').click(function(){
		$('#newsletter_subscribe_ajax_loader').css('display','inline');
		var _data = $(this).closest('form').serializeArray();
		_data.push({name:this.name,value:this.value});
		_data = $.param(_data);  					
		$.ajax({
			type:'POST',
			url:'/wp-content/themes/cognique/ajax.php',
			data:_data,
			dataType: 'json',
			success:function(msg) {
				if (msg.newsletter_subscribe_first_name_error == 1) {
					$('#newsletter_subscribe_first_name').addClass('form-field-error');
				} else {
					$('#newsletter_subscribe_first_name').removeClass('form-field-error');
				}	
				if (msg.newsletter_subscribe_last_name_error == 1) {
					$('#newsletter_subscribe_last_name').addClass('form-field-error');
				} else {
					$('#newsletter_subscribe_last_name').removeClass('form-field-error');
				}	
				if (msg.newsletter_subscribe_email_error == 1) {
					$('#newsletter_subscribe_email').addClass('form-field-error');
				} else {
					$('#newsletter_subscribe_email').removeClass('form-field-error');
				}	
				if (msg.newsletter_subscribe_email_error == 2) {
					$.fancybox({
						titleShow:false,
						scrolling:'no',
						padding:0,
						centerOnScroll:true,
						overlayColor:'#523f95',
						overlayOpacity:0.8,
						showCloseButton:true,
						href:'/modal/update-subscription/modal/true/'
					});
				}								
				if (msg.validation_error == false) {
					if (msg.newsletter_subscribe_code == 0) {
						$('#form_newsletter_subscribe_1_email').html('<strong>'+$('#newsletter_subscribe_email').val()+'</strong>');
						$('#form_newsletter_subscribe_1').css('display','inline');
						$('#form_newsletter_subscribe_2').css('display','none');
					}
				}								
				$('#newsletter_subscribe_ajax_loader').css('display','none');
			}
		});return false;
	});
	
	$('#action_button_contact_send').click(function(){
		var _data = $(this).closest('form').serializeArray();
		_data.push({name:this.name,value:this.value});
		_data = $.param(_data);  					
		$.ajax({
			type:'POST',
			url:'/wp-content/themes/cognique/ajax.php',
			data:_data,
			dataType: 'json',
			success:function(msg) {
				$('html, body').animate({scrollTop:0}, 'slow');
				if (msg.contact_name_error == 1) {
					$('#contact_name').addClass('form-field-error');
				} else {
					$('#contact_name').removeClass('form-field-error');
				}
				if (msg.contact_email_error == 1) {
					$('#contact_email').addClass('form-field-error');
				} else {
					$('#contact_email').removeClass('form-field-error');
				}	
				if (msg.contact_message_error == 1) {
					$('#contact_message').addClass('form-field-error');
				} else {
					$('#contact_message').removeClass('form-field-error');
				}
				if (msg.contact_captcha_error == 1) {
					$('#contact_captcha').addClass('form-field-error');
				} else {
					$('#contact_captcha').removeClass('form-field-error');
				}	
				if (msg.validation_error == false) {
					$('#form_contact_messages').html('<div class="successbox">Thank you for your message.</div>');
					$('#form_contact_messages').css("display","inline");	
					$('#contact_form').css("display","none");	
				} else {
					$('#form_contact_messages').html('');
					$('#form_contact_messages').css("display","none");	
					$('#contact_form').css("display","inline");	
				}	
			}
		});return false;
	});	
		
	Cufon.replace('#projects .jcarousel-list li .carousel-quote .carousel-quote-cell p',{fontFamily:'Futura Std'});
	$('#projects .jcarousel-list li .carousel-quote .carousel-quote-cell p').css("display","block");	
	
}); 

/* ]]> */
