$(function () {

	//styleswitcher
	
	
	if(!($('body').hasClass('home')))
	
	{$('a.open').removeClass('open').addClass('close').css({ 'background' : 'black url(images/demo/ThemeChangerClosed.png) no-repeat center center' });
	
	$('#colorscheme').css({left: '-170px'});	
	
}
	
	$('a.open').live('click', function(){
		
		$(this).removeClass('open').addClass('close').css({ 'background' : 'black url(images/demo/ThemeChangerClosed.png) no-repeat center center' });
	
		$('#colorscheme').animate({left: '-=170'});	
		
		return false;

	}); 
	
	
	$('a.close').live('click', function(){
		
		$(this).removeClass('close').addClass('open').css({ 'background' : 'black url(images/demo/ThemeChangerOpen.png) no-repeat center center' });
	
		$('#colorscheme').animate({left: '+=170'});	
		
		return false;
				
	}); 
	
	$('#colorscheme a').click(function(){
		
		$('#colorscheme a').css('color', '#a8a8a8');
		
		$(this).css('color', 'white');
		
		
		
	}); 



	// CUFON FONT REPLACEMENT
    Cufon.replace('h1, h2, h3, h4, p.comment_author, .button');
	Cufon.replace('h1.logo a, #featured h2', {
	color: '-linear-gradient(0=#c5c5c5, 0.02=#f3f3f3, 0.53=#e1e1e1, 0.98=#ffffff, 1=#bfbfbf)'
	});


	// HOMEPAGE ILLUSTATION / SLIDER CHANGER
    if ($('body').hasClass('home')) {

        $('#slider_switch :checkbox').removeAttr('checked');
        $('#slider_switch :checkbox').iphoneStyle({
            checkedLabel: '&larr; Illustration',
            uncheckedLabel: 'Image slider &rarr;',
            resizeContainer: false,
            resizeHandle: false
        });

        $('#slider_switch input').change(function () {
            if ($(this).attr("checked")) {
                $('.featured_text').fadeOut();
                $('#featured_slider_home').css('visibility', 'visible').fadeIn();
                $('h2.slider_title').fadeIn();
                return false;
            }

            $('.featured_text').fadeIn();
            $('#featured_slider_home').fadeOut();
            $('h2.slider_title').fadeOut();
        });

    }
    
   
	//NAVBAR  SLIDEDOWN
    $('#navbar ul').css({
        display: "none"
    });
    
    $('#navbar li').hover(function () {
        $(this).find('ul:first').css({
            visibility: "visible",
            display: "none"
        }).slideDown('fast');
    }, function () {
        $(this).find('ul:first').css({
            visibility: "hidden"
        });
    });

    $("#navbar li").has('ul').addClass('parent_nav').find('>a').append('<span class="has_children"></span>');




	//GALLERY IMAGES HOVER SCRIPT
	
	$('#portfolio a.image_item').append('<span class="image_hover"></span>');	//add span to images 		
	$('#portfolio a.video_item').append('<span class="video_hover"></span>');	// add span to videos		

	$('#portfolio li a span:not(.new_work)').css('opacity', '0').css('display', 'block') //span opacity = 0 
	
	// show / hide span on hover
	$("#portfolio a").hover(
		 function () {
			 $(this).find('.image_hover, .video_hover').stop().fadeTo('slow', .7); }, 
		function () {
	  		  $('.image_hover, .video_hover').stop().fadeOut('slow', 0);
	});



	
	//HIDE FORM LABEL ON FOCUS
	
	 $('#contact_form input, #contact_form textarea, #comment_form input, #comment_form textarea, #newsletter_form input.form_input')
	.bind("focus.labelFx", function(){
		$(this).prev().fadeOut();
	})
	.bind("blur.labelFx", function(){
		$(this).prev()[!this.value ? "fadeIn" : "fadeOut"]();
	})
	.trigger("blur.labelFx");
		
		
	// CONTACT FORM HANDLING SCRIPT - WHEN USER CLICKS "SUBMIT"
	
	$("#contact_form #form_submit").click(function(){		
				   				 		
		
		// remove "error" class from text fields
		$("form input, form textarea").focus(function() {
 			$(this).removeClass('error_input');
 			$(this).parent().find('label.error').fadeOut().remove();
		});

		// set variables
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		
		// validate "name" field
		var nameVal = $("#form_name").val();
		if(nameVal == '') {
			$("#form_name")
			.after('<label for="form_name" class="error">Please enter your name</label>')
			.addClass('error_input')				  
			hasError = true;
			$("#form_name").parent().find('label:not(.error)').hide();	
		}
	
		// validate "e-mail" field - andd error message and animate border to red color on error
		var emailVal = $("#form_email").val();
		if(emailVal == '') {
			$("#form_email")
			.after('<label for="form_email" class="error">Please enter your e-mail</label>')
			.addClass('error_input')
			hasError = true; 
			
			$("#form_email").parent().find('label:not(.error)').hide();
				
		} else if(!emailReg.test(emailVal)) {	
			$("#form_email")
			.after('<label for="form_email" class="error">Please provide a valid e-mail</label>')
			.addClass('error_input')
			hasError = true;
			$("#form_email").attr("value", "");
			$("#form_email").parent().find('label:not(.error)').hide();
		}
		
				
		// validate "message" field
		var messageVal = $("#form_message").val();
		if(messageVal == '') {
			
			$("#form_message")
			.after('<label for="form_message" class="error comment_error">Please enter your message</label>')
			.addClass('error_input')
			hasError = true;
			
			$("#form_message").parent().find('label:not(.error)').hide();
		}
		
                // if the are errors - return false
                if(hasError == true) { return false; }
            
		// if no errors are found - submit the form with AJAX
		if(hasError == false) {
			
		var dataString = $('#contact_form').serialize();

			//hide the submit button and show the loader image	
			$("#form_submit").fadeOut('fast', function () {
			$('#loader').fadeIn(); 
			});
			       
			
		// make an Ajax request
        $.ajax({
            type: "POST",
            url: "php/contact-send.php",
            data: dataString,
            success: function(){ 
           
          // on success fade out the form and show the success message
          $('#loader').hide();
          $('#contact_form input, #contact_form textarea').fadeOut('fast');
          $('.contact_info').fadeOut('fast');
           $('.success').fadeIn();    	
            }
        }); // end ajax

		 return false;  
		} 	
		
	});		
		

		
	// FOOTER TOOLTIPS
	$('.tooltip_link').tipsy({gravity: 's', fade: 'true' });	
		
		
	// FOOTER SOCIAL LIST HOVER
    $(".center_container a").hover(function () {
        $(this).filter(':not(:animated)').animate({
            top: '-=45px'
        });
    }, function () {
        $(this).animate({
            top: '0px'
        });
    });

	



	// SORTABLE PORTFOLIO DROPDOWN SCRIPT
	$('.changer_select li:first-child').addClass('active_li');
	$('.changer_select li:first-child').next('li').addClass('next_child');
	
	// on click on the dropdown list item remove "active" class from the first item and add it to clicked one
	$('.changer_select li a').click(function(){
		$('.changer_select li.active_li').removeClass('active_li'); 
		$(this).closest("li").addClass('active_li').prependTo(".changer_select");
		$('.changer_select li.next_child').removeClass('next_child');
		$('.changer_select li:first-child').next('li').addClass('next_child');
		$('.changer_select li').not('.active_li').hide();		
		$('.list_switch').addClass('show_list');
	return false;
	});
	
	
	$('.list_switch').addClass('show_list');
	
	// on click on dropdown arrow slide down the list for sorting
	$('.list_switch').live('click', function() {
		if ($(this).hasClass('show_list'))
		{
			$(this).removeClass('show_list');
			$('.changer_select li').slideDown('fast');
		}
		else
		{$(this).addClass('show_list');
			$('.changer_select li').not('.active_li').slideUp();
		}		
			return false;
	});
	



	// PORTFOLIO SWITCH BETWEEN THUMBNAILS AND TEXT COULMNS 
	
	//on click on 'List' link fade out thumbnails and show text list
	$('.portfolio_list_switch').click(function() {
		$('a.active_switch').removeClass('active_switch');	
		$(this).addClass('active_switch');
		$('.portfolio_thumbs').fadeOut('fast', function(){		
			$('.portfolio_item_list').fadeIn();		
		});
		return false;	
	});
	
	
	//on lick on 'Thumbnails' link fade out text list and show the thumbnails
	$('.portfolio_thumbs_switch').click(function(){
		$('a.active_switch').removeClass('active_switch');	
		$(this).addClass('active_switch');	
		$('.portfolio_item_list').fadeOut('fast', function(){
			$('.portfolio_thumbs').fadeIn();		
		});
		return false;	
	});
	

}); // DOCUMENT READY FUNCTION ENDS HERE


$(window).load(function() { 
	
	// check if slider exists		
	if ($('#featured_slider').length !== 0)	{
	    $('#featured_slider').nivoSlider();
	
	
		//center slider navigation on the homepage
		if( $('body').hasClass('home'))
		{
			$(".nivo-controlNav").animate({"left": "0px"}, 0);
			$(".nivo-controlNav").animate({"bottom": "10px"}, 0);
			var a_count = $(".nivo-controlNav a").size();
			a_count = parseInt(a_count);
			a_count = a_count * 28;
			var width = a_count;
			var x_pos = ((900 / 2) - (width  / 2)) - 5;
			
			$(".nivo-controlNav").animate({"left": x_pos}, 600);
		}
		
		//center slider navigation on other pages
		else
		{
			$(".nivo-controlNav").animate({"left": "0px"}, 0);
			$(".nivo-controlNav").animate({"bottom": "10px"}, 0);
			//$(".nivo-controlNav").animate({"opacity": "0"}, 0);
			
			var a_count = $(".nivo-controlNav a").size();
			a_count = parseInt(a_count);
			a_count = a_count * 28;
			var width = a_count;
			var x_pos = ((524 / 2) - (width  / 2)) - 5;
			$(".nivo-controlNav").animate({"left": x_pos}, 600);		
		}
	
	}
}); //window load function ends here

Cufon.replace('#logo a,#logo a span,h1,h2,h3,h4,#top-phone,#top-email,label,.action span', {fontFamily: 'Comfortaa'} );

var $ = jQuery.noConflict();

$(document).ready(function() {
	
		$('a.action,#fsocial li a img,.bigsubmit,.smallsubmit').hover(function(){
			$(this).animate({opacity: 0.7}, 300);
		}, function () {
			$(this).animate({opacity: 1}, 300);
		});
		
		$('.pgallery li a').mouseenter(function(e) {
            $(this).children('img').animate(200);
            $(this).children('span').fadeIn(300);
        }).mouseleave(function(e) {
            $(this).children('img').animate(200);
            $(this).children('span').fadeOut(300);
        });
		
		
		$('.ntip').tipsy({gravity: 's', fade:true});
		$('.stip').tipsy({gravity: 'n', fade:true});
		$('.etip').tipsy({gravity: 'w', fade:true});
		$('.wtip').tipsy({gravity: 'e', fade:true});
		
		
		$('#offerslide').cycle({ 
        	fx:'scrollLeft,scrollDown,scrollRight,scrollUp',
			timeout:3000,
			easing:'easeInOutBack', // easing supported via the easing plugin	
			pager:'.slidernav',
	        prev:    '#slidernavp',
	        next:    '#slidernavn',
	        pause: 1,
	        cleartypeNoBg: true,
			// callback fn that creates a thumbnail to use as pager anchor 
			pagerAnchorBuilder: function(idx, slide) { 
				return '<li><a href="#"></a></li>';
			}
    	});
    	
    	$('.twitterfeed ul,.testimonials').cycle({ 
        	fx:'scrollUp',
			timeout:5000,
			easing:'easeInOutBack',
	        cleartypeNoBg: true	
    	});
    	
    	$('.twitterfeed ul,.testimonials').hover(function() { 
    		$(this).cycle('pause');
		}, function() { 
    		$(this).cycle('resume'); 
		});
		
		$('.slidernav li a,#slidernavp,#slidernavn').click(function() { 
    		$('#offerslide').cycle('pause'); 
		});
		
		$('#offerslider').hover(function() { 
    		$('#slidernavp,#slidernavn').fadeIn('slow');
		}, function() { 
    		$('#slidernavp,#slidernavn').fadeOut('slow'); 
		});
		
		$('#pgallery li a').mouseenter(function(e) {
            $(this).children('img').animate(300);
            $(this).children('span').fadeIn(400);
        }).mouseleave(function(e) {
            $(this).children('img').animate(300);
            $(this).children('span').fadeOut(400);
        });
			
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animation_speed: 'normal',
			theme: 'dark_rounded'
			});
			
		$('input[type="text"],select,textarea').focus(function () {
			$(this).removeClass("inputerror");
		});
			
});


$(document).ready(function() {

		$('#quote_form-submit').click(function () {
          
        //Get the data from all the fields
        
        var regemail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  		 
        var ajaxquote_name = $('input[name="quote_form-name"]');
        var ajaxquote_email = $('input[name="quote_form-email"]');
        var ajaxquote_phone = $('input[name="quote_form-phone"]');
        var ajaxquote_company = $('input[name="quote_form-company"]');
        var ajaxquote_website = $('input[name="quote_form-website"]');
        var ajaxquote_pages = $('select[name="quote_form-pages"]');
        var ajaxquote_budget = $('select[name="quote_form-budget"]');
          
        if (ajaxquote_name.val()=='') {
            ajaxquote_name.addClass('inputerror');
            return false;
        } else ajaxquote_name.removeClass('inputerror');
        
        if (ajaxquote_email.val()=='') {
            ajaxquote_email.addClass('inputerror');
            return false;
        } else ajaxquote_email.removeClass('inputerror');
        
        if (ajaxquote_phone.val()=='') {
            ajaxquote_phone.addClass('inputerror');
            return false;
        } else ajaxquote_phone.removeClass('inputerror');
        
        if (ajaxquote_company.val()=='') {
            ajaxquote_company.addClass('inputerror');
            return false;
        } else ajaxquote_company.removeClass('inputerror');
        
        if (ajaxquote_website.val()=='') {
            ajaxquote_website.addClass('inputerror');
            return false;
        } else ajaxquote_website.removeClass('inputerror');
        
        if (ajaxquote_pages.val()=='') {
            ajaxquote_pages.addClass('inputerror');
            return false;
        } else ajaxquote_pages.removeClass('inputerror');
        
        if (ajaxquote_budget.val()=='') {
            ajaxquote_budget.addClass('inputerror');
            return false;
        } else ajaxquote_budget.removeClass('inputerror');
		
		if(regemail.test(ajaxquote_email.val()) == false) {
  			ajaxquote_email.addClass('inputerror');
            return false;
        } else ajaxquote_email.removeClass('inputerror');
        
        
        var data = $('#quote_form').serialize();
          
        //start the ajax  
        $.ajax({  
            //this is the php file that processes the data and send mail  
            url: "quoteform.php",   
              
            //GET method is used  
            type: "GET",  
  
            //pass the data           
            data: data,       
              
            //Do not cache the page  
            cache: false,  
              
            //success  
            success: function (html) {                
                //if process.php returned 1/true (send mail success)  
                if (html==1) {                    
                    //hide the form  
                    $('#quote_form').hide();                   
                      
                    //show the success message  
                    $('#quote_form-successmsg').fadeIn('slow');  
                      
                //if process.php returned 0/false (send mail failed)  
                } else alert('Sorry, unexpected error. Please Refresh the Page & Try Again.');                 
            }         
        });  
          
        //cancel the submit button default behaviours  
        return false;
        
        });
        
        
        
        $('#newsletter_form-submit').click(function () {
          
        //Get the data from all the fields
        
        var regemail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        
        //Getting the Form Fields and Storing it into a Javascript Variable
        
        var ajaxnewsletter_email = $('input[name="newsletter_form-email"]');
        
        //Starting the Validation
        
        if (ajaxnewsletter_email.val()=='') {
            ajaxnewsletter_email.addClass('inputerror');
            return false;
        } else ajaxnewsletter_email.removeClass('inputerror');
        
		if(regemail.test(ajaxnewsletter_email.val()) == false) {
  			ajaxnewsletter_email.addClass('inputerror');
            return false;
        } else ajaxnewsletter_email.removeClass('inputerror');
        
        //Ending the Validation
        
        
        
        //Storing All the Form Values into a Javascript Variable
        
        var data = $('#newsletter_form').serialize();
          
        //start the ajax  
        $.ajax({  
            //this is the php file that processes the data and send mail  
            url: "newsletter.php",   
              
            //GET method is used  
            type: "GET",  
  
            //pass the data           
            data: data,       
              
            //Do not cache the page  
            cache: false,  
              
            //success  
            success: function (html) {                
                //if process.php returned 1/true (send mail success)  
                if (html==1) {                    
                    //hide the form  
                    $('#subscribe').hide();                   
                      
                    //show the success message  
                    $('#newsletter_form-successmsg').fadeIn('slow');  
                      
                //if process.php returned 0/false (send mail failed)  
                } else alert('Sorry, unexpected error. Please Refresh the Page & Try Again.');                 
            }         
        });  
          
        //cancel the submit button default behaviours  
        return false;
        
        });

});
