/* Author: Lynsey Gwin
*/
jQuery('document').ready(function(){
	
// show a simple loading indicator
var loader = jQuery('<div id="loader"><img src="img/loading.gif" alt="loading..." /></div>')
.css({position: "relative", top: "1em", left: "25em"})
.appendTo("body")
.hide();

jQuery("#result").hide();

jQuery().ajaxStart(function() {
		loader.show();
	}).ajaxStop(function() {
		loader.hide();
	}).ajaxError(function(a, b, e) {
		throw e;
	});

var v = jQuery("#contact-form").validate({
	submitHandler: function(form) {
	jQuery(form).ajaxSubmit({
		target: "#result"
	});
	jQuery("#result").show();

}
});
	// Nav Hovers!
	jQuery('a#screenprinting-link')
		.css( {backgroundPosition: "0 -90px"} )
		.mouseover(function(){
			jQuery(this).stop().animate({backgroundPosition:"(0 -14px)"}, {duration:500})
		}).mouseout(function(){
			jQuery(this).stop().animate({backgroundPosition:"(0 -90px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0 -90px"})
			}})
		});
	jQuery('a#embroidery-link')
		.css( {backgroundPosition: "-130px -90px"} )
		.mouseover(function(){
			jQuery(this).stop().animate({backgroundPosition:"(-130px -14px)"}, {duration:500})
		}).mouseout(function(){
			jQuery(this).stop().animate({backgroundPosition:"(-130px -90px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "-130px -90px"})
			}})
		});
	jQuery('a#showroom-goods-link')
		.css( {backgroundPosition: "-211px -90px"} )
		.mouseover(function(){
			jQuery(this).stop().animate({backgroundPosition:"(-211px -14px)"}, {duration:500})
		}).mouseout(function(){
			jQuery(this).stop().animate({backgroundPosition:"(-211px -90px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "-211px -90px"})
			}})
		});
	jQuery('a#about-us-link')
		.css( {backgroundPosition: "-351px -90px"} )
		.mouseover(function(){
			jQuery(this).stop().animate({backgroundPosition:"(-351px -14px)"}, {duration:500})
		}).mouseout(function(){
			jQuery(this).stop().animate({backgroundPosition:"(-351px -90px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "-351px -90px"})
			}})
		});
	jQuery('a#contact-us-link')
		.css( {backgroundPosition: "-433px -90px"} )
		.mouseover(function(){
			jQuery(this).stop().animate({backgroundPosition:"(-433px -14px)"}, {duration:500})
		}).mouseout(function(){
			jQuery(this).stop().animate({backgroundPosition:"(-433px -90px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "-433px -90px"})
			}})
		});
	jQuery('a#faqs-link')
		.css( {backgroundPosition: "-531px -90px"} )
		.mouseover(function(){
			jQuery(this).stop().animate({backgroundPosition:"(-531px -14px)"}, {duration:500})
		}).mouseout(function(){
			jQuery(this).stop().animate({backgroundPosition:"(-531px -90px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "-531px -90px"})
			}})
		});
								  
	jQuery("#map").gMap({
		latitude:30.418526,
		longitude:-91.090143,
		zoom:15,
		controls:false,
		scrollwheel:false,
		markers:[{latitude: 30.418526, longitude: -91.090143, html: "Keys Graphics"}]
/*		icon:{
			image:              "",
			shadow:             false,
			iconsize:           [19, 21],
			shadowsize:         false,
			iconanchor:         [4, 19],
			infowindowanchor:   [8, 2]	
			}*/
		});
								  
	
	jQuery('#home-side div.contact').noisy({
		'intensity' : 1.5,
		'size' : 200,
		'opacity' : 0.1,
		'fallback' : '',
		'monochrome' : false
	}).css('background-color', '#D5D1CC');
	
	jQuery('#screenprinting-container .box').noisy({
		'intensity' : 1.5,
		'size' : 200,
		'opacity' : 0.1,
		'fallback' : '',
		'monochrome' : false
	}).css('background-color', '#d8d3d0');	
	
	jQuery('#embroidery-container .box').noisy({
		'intensity' : 1.5,
		'size' : 200,
		'opacity' : 0.1,
		'fallback' : '',
		'monochrome' : false
	}).css('background-color', '#a19a94');	
	
	jQuery('#showroom-goods-container .box').noisy({
		'intensity' : 1.5,
		'size' : 200,
		'opacity' : 0.1,
		'fallback' : '',
		'monochrome' : false
	}).css('background-color', '#e6e1de');	
	
	jQuery('#about-us-container .box').noisy({
		'intensity' : 1.5,
		'size' : 200,
		'opacity' : 0.1,
		'fallback' : '',
		'monochrome' : false
	}).css('background-color', '#8a837c');	
	
	jQuery('#contact-us-container .box').noisy({
		'intensity' : 1.5,
		'size' : 200,
		'opacity' : 0.1,
		'fallback' : '',
		'monochrome' : false
	}).css('background-color', '#dad3cd');
	
/* HOME PAGE SLIDESHOW -------------------------------------*/
	
	jQuery('#home-slideshow') 
		.cycle({ 
			fx:     'turnDown', 
			speed:  'fast', 
			pager:	'#home-buttons',
			pause:   true,
			timeout: 0,
			pagerAnchorBuilder: function(idx, slide) {
				return '';
			}
		});	
		
	jQuery('#slide1').click(function() { 
		jQuery('#home-slideshow').cycle(0);
    	return false; 
	}); 
 
	jQuery('#slide2').click(function() {  
		jQuery('#home-slideshow').cycle(1);  
    	return false;  
	}); 	
	
	jQuery('#slide3').click(function() { 
		jQuery('#home-slideshow').cycle(2); 
    	return false; 
	}); 
 
	jQuery('#slide4').click(function() {  
		jQuery('#home-slideshow').cycle(3);  
    	return false;  
	});
	
/* INTERIOR PAGE SLIDESHOWS -------------------------------------*/
	
	jQuery('#screenprinting-slideshow') 
		.before('<div class="slideshow-nav">') 
		.cycle({ 
			fx:     'turnDown', 
			speed:  'fast', 
			pager:  '#screenprinting-container .slideshow-nav' 
	});
		
	jQuery('#embroidery-slideshow') 
		.before('<div class="slideshow-nav">') 
		.cycle({ 
			fx:     'turnDown', 
			speed:  'fast', 
			pager:  '#embroidery-container .slideshow-nav' 
	});
		
	jQuery('#showroom-goods-slideshow') 
		.before('<div class="slideshow-nav">') 
		.cycle({ 
			fx:     'turnDown', 
			speed:  'fast', 
			pager:  '#showroom-goods-container .slideshow-nav' 
	});
		
/* ONE-PAGE SCROLLING CONTROLS -------------------------------------*/

/** Handles window location based on hash **/	
	if(window.location.hash=="" || window.location.hash=="#home" || window.location.hash=="#home1"){
		$("a#home-link").addClass("current");
		$(window).scrollTop(0);
	};
	
	if(window.location.hash=="#screenprinting" || window.location.hash=="#screenprinting1"){
		$('a#screenprinting-link').addClass('current');
		$(window).scrollTop(755);
	};
	
	if(window.location.hash=="#embroidery" || window.location.hash=="#embroidery1"){
		$('a#embroidery-link').addClass('current');
		$(window).scrollTop(1553);
	};	
	if(window.location.hash=="#showroom-goods" || window.location.hash=="#showroom-goods1"){
		$('a#showroom-goods-link').addClass('current');
		$(window).scrollTop(2340);
	};
	
	if(window.location.hash=="#about-us" || window.location.hash=="#about-us1"){
		$('a#about-us-link').addClass('current');
		$(window).scrollTop(3127);
	};	
	
	if(window.location.hash=="#contact-us" || window.location.hash=="#contact-us1"){
		$('a#contact-us-link').addClass('current');
		$(window).scrollTop(3941);
	};
	
	if(window.location.hash=="#faqs" || window.location.hash=="#faqs1"){
		$('a#faqs-link').addClass('current');
		$(window).scrollTop(4711);
	};	
/** Handles hash and current class on navigation based on scrolltop location **/	
	$(window).scroll(function() {
		
		var scroller=$(window).scrollTop();
					
		if(scroller<=754){
			$('#main-nav li a').removeClass('current');
			$('a#home-link').addClass('current');
			window.location.hash="#home1";
		}else if(scroller>=755 && scroller<=1552){
			$('#main-nav li a').removeClass('current');
			$('a#screenprinting-link').addClass('current');
			window.location.hash="#screenprinting1";
		}else if(scroller>=1553 && scroller<=2339){
			$('#main-nav li a').removeClass('current');
			$('a#embroidery-link').addClass('current');
			window.location.hash="#embroidery1";
		}else if(scroller>=2340 && scroller<=3126){
			$('#main-nav li a').removeClass('current');
			$('a#showroom-goods-link').addClass('current');
			window.location.hash="#showroom-goods1";
		}else if(scroller>=3127 && scroller<=3940){
			$('#main-nav li a').removeClass('current');
			$('a#about-link').addClass('current');
			window.location.hash="#about-us1";		
		}else if(scroller>=3941 && scroller<=4710){
			$('#main-nav li a').removeClass('current');
			$('a#about-link').addClass('current');
			window.location.hash="#contact-us1";			
		}else if(scroller>=4711){
			$('#main-nav li a').removeClass('current');
			$('a#faqs-link').addClass('current');
			window.location.hash="#faqs1";				
		}

	});
	
/** Handles current class on navigation based on click **/
	$("a.anchor-link").anchorAnimate()
	
});

/*****
***	Anchor Slider by Cedric Dugas ***
*** Http://www.position-absolute.com ***
Never have an anchor jumping your content, slide it. Don't forget to put an id to your anchor
*****/
jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}	
