$(document).ready(function() {

	/////////////////////////////////////////////////
	//! SHOWCASE GALLERY
	////////////////////////////////////////////////

initgallery = function(){

    var gallery = $('#thumbs').galleriffic({
        delay:                     3000, // in milliseconds
        numThumbs:                 8, // The number of thumbnails to show page
        preloadAhead:              3, // Set to -1 to preload all images
        enableTopPager:            false,
        enableBottomPager:         false,
        maxPagesToShow:            1,  // The maximum number of pages to display in either the top or bottom pager
        imageContainerSel:         '#slideshow', // The CSS selector for the element within which the main slideshow image should be rendered
        controlsContainerSel:      '#controls', // The CSS selector for the element within which the slideshow controls should be rendered
        captionContainerSel:       '#caption', // The CSS selector for the element within which the captions should be rendered
        loadingContainerSel:       '#loading', // The CSS selector for the element within which should be shown when an image is loading
        renderSSControls:          false, // Specifies whether the slideshow's Play and Pause links should be rendered
        renderNavControls:         false, // Specifies whether the slideshow's Next and Previous links should be rendered
        playLinkText:              'Play',
        pauseLinkText:             'Pause',
        prevLinkText:              'Previous',
        nextLinkText:              'Next',
        nextPageLinkText:          'Next &rsaquo;',
        prevPageLinkText:          '&lsaquo; Prev',
        enableHistory:             false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes
        enableKeyboardNavigation:  false, // Specifies whether keyboard navigation is enabled
        autoStart:                 false, // Specifies whether the slideshow should be playing or paused when the page first loads
        syncTransitions:           false, // Specifies whether the out and in transitions occur simultaneously or distinctly
        defaultTransitionDuration: 1200, // If using the default transitions, specifies the duration of the transitions
        onSlideChange:             undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
        onTransitionOut:           undefined, // accepts a delegate like such: function(slide, caption, isSync, callback) { ... }
        onTransitionIn:            undefined, // accepts a delegate like such: function(slide, caption, isSync) { ... }
        onPageTransitionOut:       undefined, // accepts a delegate like such: function(callback) { ... }
        onPageTransitionIn:        undefined, // accepts a delegate like such: function() { ... }
        onImageAdded:              undefined, // accepts a delegate like such: function(imageData, $li) { ... }
        onImageRemoved:            undefined  // accepts a delegate like such: function(imageData, $li) { ... }
    });
    
};
	
	/////////////////////////////////////////////////
	//! Email
	////////////////////////////////////////////////
	
	$("#name").focus(function(){
		var nameVal = $("#name").val();
		if(nameVal == 'please enter your name'){
			$(this).val('');
		}
	});
	
	$("#name").blur(function(){
		var nameVal = $("#name").val();
		if(nameVal == ''){
			$(this).val('please enter your name');
		}
	});
	
	$("#email").focus(function(){
		var emailVal = $("#email").val();
		if(emailVal == 'please enter your email address' || emailVal == 'please enter a valid email address'){
			$(this).val('');
		}
	});
	
	$("#email").blur(function(){
		var emailVal = $("#email").val();
		if(emailVal == ''){
			$(this).val('please enter your email address');
		}
	});
	
	$("#message").focus(function(){
		var messageVal = $("#message").val();
		if(messageVal == 'please enter a message'){
			$(this).val('');
		}
	});
	
	$("#message").blur(function(){
		var messageVal = $("#message").val();
		if(messageVal == ''){
			$(this).val('please enter a message');
		}
	});
	
	$("#spam").focus(function(){
		var spamVal = $("#spam").val();
		$(this).val('');
	});
	
	$("#spam").blur(function(){
		var spamVal = $("#spam").val();
		if(spamVal == ''){
			$(this).val('please answer the question');
		}
	});
		
	$("#submit").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var nameVal = $("#name").val();
		if(nameVal == '' || nameVal == 'please enter your name') {
			$("#name").val('please enter your name');
			$("#name").effect("highlight", {color:"#999999"}, 800);
			hasError = true;
		}
		
		var emailFromVal = $("#email").val();
		if(emailFromVal == '' || emailFromVal == 'please enter your email address') {
			$("#email").val('please enter your email address');
			$("#email").effect("highlight", {color:"#999999"}, 800);
			hasError = true;
		} else if(!emailReg.test(emailFromVal) || emailFromVal == 'please enter a valid email address') {	
			$("#email").val('please enter a valid email address');
			$("#email").effect("highlight", {color:"#999999"}, 800);
			hasError = true;
		}
		
		var messageVal = $("#message").val();
		if(messageVal == '' || messageVal == 'please enter a message') {
			$("#message").val('please enter a message');
			$("#message").effect("highlight", {color:"#999999"}, 800);			
			hasError = true;
		}
		
		var spamVal = $("#spam").val();
		if(spamVal == '' || spamVal == 'please answer the question') {
			$("#spam").val('please answer the question');
			$("#spam").effect("highlight", {color:"#999999"}, 800);			
			hasError = true;
		}else if(spamVal != 'artspec') {
			$("#spam").val('wrong answer');
			$("#spam").effect("highlight", {color:"#999999"}, 800);			
			hasError = true;
		}
		
		var companyVal = $("#company").val();
		var subjectVal = $("#subject").val();
		var toVal = $("#to").val();
		
		
		if(hasError == false) {
			$(".thanks").html('');
			
			$.post("sendemail.php",
   				{ name: nameVal, company: companyVal, email: emailFromVal, subject: subjectVal, to: toVal, message: messageVal },
   					function(data){
						//$("#contactform").slideUp("normal", function() {				   
							//alert("success");
							$(".thanks").html('<p><strong>Thank you!</strong><br/>Your email has been sent. We will get back to you shortly.</p>');
							$("#name").val('');
							$("#company").val('');	
							$("#email").val('');
							$("#subject").val('Choose Subject');
							$("#to").val('Anyone');		
							$("#message").val('');	
							$("#spam").val('');									
						//});
   					}
				 );
		}
		
		return false;
	});


	/////////////////////////////////////////////////
	//! Smooth Scrolling
	////////////////////////////////////////////////
	

$(function(){

    $('a[href*=#]').click(function() {
    
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
        
            var $target = $(this.hash);
            
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            
            if ($target.length) {
            
                var targetOffset = $target.offset().top;
                
                $('html,body').animate({scrollTop: targetOffset}, 800);
                    
                return false;
                
            }
            
        }
        
	});
	
});


	/////////////////////////////////////////////////
	//! Tooltip
	////////////////////////////////////////////////
	

$(function() {

    $("#tooltip").hide();

    $(".ourpromise").mousemove(function(e){
        $("#tooltip").fadeIn("fast");
        $("#tooltip").css({
            top: (e.pageY - 140) + "px",
            left: (e.pageX - 110) + "px"
        });
    });
    $(".ourpromise").mouseout(function(e){
        $("#tooltip").fadeOut("fast");
    });

});


	/////////////////////////////////////////////////
	//! Showcase
	////////////////////////////////////////////////
	

		bindelements = function(){

			$.ajaxSetup ({  
				cache: false  
			});
			  
			var ajax_load = "<img src='images/loading.gif' alt='loading...' />";  
       
			//  load() functions  
			var loadUrl = "showcase_loader.php"; 
			 
			$("ul#showcaselist li a").click(function(){  
				$("#load_showcase").html(ajax_load).load(loadUrl, {whichshowcase: this.id});
				return false;  
			});  
	
		};


	/////////////////////////////////////////////////
	//! GOOGLE MAPS AJAX
	////////////////////////////////////////////////		
		
		$(function() {
		
		$.ajaxSetup ({  
				cache: false  
			});
			  
			var ajax_load = "<img src='images/loading.gif' alt='loading...' />";  
       
			//  load() functions  
			var loadUrl = "map_loader.php"; 
			 
			$("a#load_map").click(function(){  
				$("#mapholder").html(ajax_load).load(loadUrl);
				return false;  
			});
			
		});
	
		bindelements();
		initgallery();

});