$(window).load(function() {
	
	//menu config
	var menumargin = Math.round(($(".banner").height()-20)/2);
	$(".menumargin").height($(".banner").height());
	$(".banner").css('position', 'fixed');
	$(".site_top .menu > ul > li > a").css('padding-top', menumargin + "px");
	$(".site_top .menu > ul > li > a").css('padding-bottom', menumargin + "px");
	$(".site_top .menu").show();
	
	//build menu with ID="myslidemenu" on page:
	jqueryslidemenu.buildmenu("topmenu", arrowimages);
	
	/////////////////
	///  Cookie ///
	////////////////
	
	if($.cookie('footer_content')==0){
		$.cookie('footer_content','0');
		$('.footer_content').hide();
		$('.footer .center .footer_open').show();
		$('.footer .center .footer_close').hide();
	}else{
		$('.footer_content').show();
		$('.footer .center .footer_close').show();
		$('.footer .center .footer_open').hide();
	}
	
	/////////////////
	// nivoSlider //
	////////////////
	
    $('#slider').nivoSlider({
        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
        animSpeed:1000, // Slide transition speed
        pauseTime:5000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
		prevText: '<span class="left_arrow"></span>', // Prev directionNav text
        nextText: '<span class="right_arrow"></span>', // Next directionNav text
    });
	$('.nivoSlider').nivoSlider({
        effect:'random', // Specify sets like: 'fold,fade,sliceDown'
        startSlide:0, // Set starting Slide (0 index)
		prevText: '<span class="left_arrow"></span>', // Prev directionNav text
        nextText: '<span class="right_arrow"></span>', // Next directionNav text
    });
	$('.nivo-controlNav').hide();
	
	//////////////////
	// easySlider //
	/////////////////
	
	$(".latestWorks").easySlider({
		auto: true, 
		continuous: true,
		controlsShow:true,
		pause:5000,
		numeric: true,
		numericId: 'control-latestWorks'
	});
	$(".easySlider").easySlider({
		auto: false, 
		continuous: true,
		controlsShow:true,
		numeric: false
	});
	
});
$(document).ready(function(){

	/////////////////////////////
	// contact form control //
	/////////////////////////////
	
	$('.input, .textarea').focus(function() {
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
	}).blur(function() {
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	//contact form sending
	function eMailControl(value)
	{
		var pattern = "^"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"@"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"[\.]"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"$";
		r = new RegExp(pattern, "g");
		return r.test(value);
	}
	function mailFormControl(f,c){
		$(".alert" , c).hide();
		var alertmessage = "Please fill in all fields";
		if(f.name.value == f.name.defaultValue){
			$(".alert" , c).html("<span class='warning'>Please type your name!</span>");
		}else if(!eMailControl(f.mail.value)){
			$(".alert" , c).html("<span class='warning'>Please type a valid email!</span>");
		}else if(f.subject.value == f.subject.defaultValue){
			$(".alert" , c).html("<span class='warning'>Please include a subject!</span>");
		}else if(f.message.value == f.message.defaultValue){
			$(".alert" , c).html("<span class='warning'>Please compose a message!</span>");
		}else{
			$(".alert" , c).html("<span class='sending'>Your message is sending...</span>");
			$.post("mailpost.php", 	{ 	name:f.name.value, 
										mail:f.mail.value,
										subject:f.subject.value,
										phone:f.phone.value,
										message:f.message.value
									},
		   function(data) {
		   	if(data==1){
		   		$(".alert" , c).html("<span class='sent'>Your message has been sent!</span>");
		   		f.name.value = f.name.defaultValue;
		   		f.mail.value = f.mail.defaultValue;
		   		f.subject.value = f.subject.defaultValue;
		   		f.message.value = f.message.defaultValue;
		   		f.phone.value = f.phone.defaultValue;
		   	}else{
			 	$(".alert" , c).html("<span class='error'>Please try again!</span>");
			}
		   });
		}
		$(".alert" , c).fadeIn();
	} 
	$(".footer_contact .button").click(function() {
		mailFormControl(document.footercontact,".footer_contact");
	});
	$(".contact .button").click(function() {
		mailFormControl(document.contentcontact,".contact");
	});
	//footer content
	$(".footer .center .footer_open").click(function() {
		$.cookie('footer_content','1');
		$('html, body').animate({scrollTop : $(this).offset().top},500);
		$(".footer_content").slideDown("fast");
		$(".footer .center .footer_open").hide();
		$(".footer .center .footer_close").show();
	});
	$(".footer .center .footer_close").click(function() {
		$.cookie('footer_content','0');
		$(".footer_content").slideUp("fast");
		$(".footer .center .footer_close").hide();
		$(".footer .center .footer_open").show();
	});
	//back to top
	$(".divider span").click(function() {
		$('html, body').animate({scrollTop : 0},500);
	});
	//tab control
	$(".tabs div").hide();
	$(".tabs").find("div:first").show();
	$('.tabs > ul.titles li').click(function(){
		
		$(this).parent().find("li").removeClass('selected');
		$(this).addClass('selected');
		$(this).parent().parent().children('.tabs div.a_tab').slideUp('fast');
		$(this).parent().parent().children('.tabs div.a_tab:eq(' + $('.tabs > ul.titles li').index(this) + ')').slideDown('fast');
		
	}).mouseover(function() {
		$(this).addClass('mouseover');
	}).mouseout(function() {
		$(this).removeClass('mouseover');
	});
	//toggle config
	$(".toggle p").hide();
	$(".toggle .click").click(function () {
	  $(this).toggleClass("active").next().slideToggle("fast");
    });
	//footer bottom
	if($(document.body).height()<$(window).height()){
		var h = $(window).height()-$(document.body).height();
		$('.fixfooter').height(h);
	}	
	
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
  			animation_speed: 'fast', /* fast/slow/normal */
			slideshow: 5000, /* false OR interval time in ms */
			autoplay_slideshow: false, /* true/false */
			opacity: 0.80, /* Value between 0 and 1 */
			show_title: true, /* true/false */
			allow_resize: true, /* Resize the photos bigger than viewport. true/false */
			theme: 'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
			deeplinking: true, /* Allow prettyPhoto to update the url to enable deeplinking. */
			keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
			social_tools: '<div class="pp_social"><div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="facebook"><iframe src="http://www.facebook.com/plugins/like.php?locale=en_US&href='+location.href+'&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe></div></div>', /* html or false to disable */
			gallery_markup: ''
  	});
  	

});
