var HY   =   {};

// setup Shadowbox configuration
Shadowbox.loadSkin('classic', '/js/shadowbox/skin/'); // use the "classic" skin


$(document).ready( function()
{
	//	initiate shadowbox
	Shadowbox.init();

	//	create tabs for atists page
    $('.tab_list').tabs();
    
	$('.validateForm').validate();

    $('.eventDetails').hide();

    $('.show_eventDetails').each( function()
	{
		$(this).click(function()
		{
			$("#" + $(this).attr('id') + '_details').slideToggle();
			
			return false;
		});
	});
    
	//	make a formEraserHelper for each input & textarea field
	$('#newsletter_email, #search_term, #s').each( function()
	{
		var fieldName	=	$(this).attr('name');
		HY[fieldName]	=	new HY.formEraserHelper($(this));
	});


	//	IE hover fix for dropdown menus
	sfHover = function() {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			};
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			};
		}
	};
	if ( window.attachEvent ){ window.attachEvent("onload", sfHover);}

	//	product + calendar rotater
    $('#product_rotator').each( function(i)
    {
        HY[$(this).attr('id')+'_'+i]    =   new HY.Rotator( $(this), 'items', 'item', 300 );
    });

	//	product + calendar rotater
    $('.tour_dates').each( function(i)
    {
        HY[$(this).attr('id')+'_'+i]    =   new HY.RotatorCal( $(this), 'dates', 'date', 175 );
    });



    
});


HY.Rotator   =   function( thisObj, itemWrap, items, distance )
{
    var cc                  =   this;           					//  cached 'this'
    this.pane_wrap          =   thisObj.find('.'+itemWrap);
	this.paneWrapHeight		=	parseInt(cc.pane_wrap.height(), 10, 10);
	this.outerWrap			=	this.pane_wrap.parent();
    this.panes              =   thisObj.find('.'+items);             //  individual product panes
    this.prevBtn            =   thisObj.find('.prev');				//	previous button
    this.nextBtn          	=   thisObj.find('.next');				//	next button
	this.pane_count			=	this.panes.length;					//	# of panes
    this.currentSlide		=	1;									//	pointer of which pane is currently shown
	this.slideDistance		=	distance;
	this.totalSlides		=	thisObj.find('.third').length;
	this.lastSlide			=	'0';
	
	//	when the right button is clicked
	this.nextBtn.click(function()
	{
		if ( cc.currentSlide < cc.totalSlides-1 && cc.totalSlides >= 2  )
		{
			var newMarginTop = parseInt( thisObj.find('.third:eq('+cc.currentSlide+')').position().top - 20 , 10);
			cc.lastSlide = newMarginTop;
				
	        cc.pane_wrap.animate(
	        { 
	        	marginTop: "-=" + newMarginTop + "px"
	        }, 
			500 );
			
			cc.currentSlide++;
		}
		else if( cc.currentSlide == cc.totalSlides-1 )
		{
			var heightEnd =  cc.paneWrapHeight - cc.outerWrap.height();
			heightEnd = "-" + heightEnd + "px";
			
			cc.pane_wrap.animate(
			{
				marginTop: heightEnd
			},
			500 );
			
			cc.currentSlide++;
			
		}
		
		$(this).blur();
        return false;
	});
	
	//	when the left button is clicked
 	this.prevBtn.click(function()
	{
		if ( cc.currentSlide == cc.totalSlides)
		{
			var lastHeight = $('.item:last').height() + 30;
			cc.pane_wrap.animate(
	        { 
	        	marginTop: "+=" + lastHeight + "px"
	        }, 
			500 );
			cc.currentSlide--;
		}
		
		else if ( cc.currentSlide > 2 ) 
		{
			cc.currentSlide--;
						
	        cc.pane_wrap.animate(
	        { 
	        	marginTop: "+=" + cc.lastSlide + "px"
	        }, 
			500 );
		}
		
		else if( cc.currentSlide == 2 ) 
		{
			cc.currentSlide = 1;
			
			cc.pane_wrap.animate(
			{
				marginTop: "0px"
			},
			500 );
		}

        $(this).blur();
        return false;
	});
    
};	//	end HY.Rotator


HY.RotatorCal   =   function( thisObj, itemWrap, items, distance )
{
    var cc                  =   this;           					//  cached 'this'
    this.pane_wrap          =   thisObj.find('.'+itemWrap);
	this.paneWrapHeight		=	parseInt(cc.pane_wrap.height(), 10);
	this.outerWrap			=	this.pane_wrap.parent();
    this.panes              =   thisObj.find('.'+items);             //  individual product panes
    this.prevBtn            =   thisObj.find('.prev');				//	previous button
    this.nextBtn          	=   thisObj.find('.next');				//	next button
	this.pane_count			=	this.panes.length;					//	# of panes
    this.currentSlide		=	1;									//	pointer of which pane is currently shown
	this.slideDistance		=	distance;
	this.totalSlides		=	parseInt(parseInt(this.paneWrapHeight, 10) / parseInt(this.slideDistance, 10), 10);
	

	//	when the right button is clicked
	this.nextBtn.click(function()
	{
		if ( cc.currentSlide < cc.totalSlides-1 && cc.totalSlides >= 2  )
		{
	        cc.pane_wrap.animate(
	        { 
	        	marginTop: "-=" + cc.slideDistance + "px"
	        }, 
			500 );
			
			cc.currentSlide++;
		}
		else
		{
			var heightEnd =  cc.paneWrapHeight - cc.outerWrap.height();
			heightEnd = "-" + heightEnd + "px";
			
			cc.pane_wrap.animate(
			{
				marginTop: heightEnd
			},
			500 );
		}
		
		$(this).blur();
        return false;
	});
	
	//	when the left button is clicked
 	this.prevBtn.click(function()
	{
		if ( cc.currentSlide > 1 ) 
		{
	        cc.pane_wrap.animate(
	        { 
	        	marginTop: "+="+cc.slideDistance+"px"
	        }, 
			500 );
			
			cc.currentSlide--;
		}
		else {
			
			cc.pane_wrap.animate(
			{
				marginTop: "0px"
			},
			500 );
		}

        $(this).blur();
        return false;
	});
    
    
};	//	end HY.RotatorCal


HY.formEraserHelper	=	function(fieldObj)
{
	var obj				=	this;					// 	cached "this"
	this.fieldObj		=	fieldObj;				//	the form field jQuery object
	this.initialValue	=	this.fieldObj.val();	//	initial value of the form field
	
	//	when focused on, if the value hasn't been changed, empty it
	this.fieldObj.focus(function()
	{
		if ( $(this).val() == obj.initialValue )
		{
			$(this).val('');
		}
	});
	
	//	when blurred, if the field is empty, populate it 
	this.fieldObj.blur(function()
	{
		if ( $(this).val() === '' )
		{
			$(this).val(obj.initialValue);
		}
	});
};	//	end formEraserHelper