/**
 * @author Jason Adkison - Webdesigner, Towerbridge Technologies, LLC
 */
$(document).ready(function(){	
	
	// Login Panel
	$("a#toggleLogin,a#closeLogin").click(function(){
		var panelHeight = $("div#panel").css('height');
		var loginMargin = $("div#panel div#login").css('margin-top');		
		togglePanel(panelHeight,loginMargin); 
		return false;
	});
	
	// Flash messages, click to hide
    $("div.flash a.clickClose").click(function(){
        $(this).parent().animate({top:"+=10px"})
			.animate({top:"-5000px"}, 800, function(){ $(this).remove(); return false; });
			return false;
    });
	
	
    $("#go").click(function(){
      $("#block").animate({ 
        width: "70%",
        opacity: 0.4,
        marginLeft: "0.6in",
        fontSize: "3em", 
        borderWidth: "10px"
      }, 1500 );
    });
	
	
	/* Select the default form text on click */
	$("input.clickSelect").focus(function(){
		$(this).select();
	});

		
	// Panel Toggle Function
	function togglePanel(panelHeight,loginMargin){		
		if($("div#panel").hasClass('errors')){
			if(panelHeight == '0px'){
				panelHeight = '132px';
				loginMargin = '0px';				
			} else {
				panelHeight = '0px';
				loginMargin = '-80px';
			}
		} else {
			if(panelHeight == '0px'){
				panelHeight = '80px';
				loginMargin = '0px';
			} else {
				panelHeight = '0px';
				loginMargin = '-80px';
			}			
		}
		$("div#panel").animate({
			height: panelHeight
		}, { "duration": 600 });	
		$("div#panel div#login").animate({
			marginTop: loginMargin
		}, 600);					
	}	
	
	
	/* Dropdown Menus */
	function addDropdown(){
		$(this).children("div").slideDown('fast');
		$(this).addClass("hovering current");
	}

	function removeDropdown(){
		$(this).children("div").slideUp('fast');
		$(this).removeClass("hovering current");
	}		
	
	var dropDownConfig = {
		interval: 100,
		sensitivity: 1,
		over: addDropdown,
		timeout: 400,
		out: removeDropdown
	};
	
	$("li.dropDown").hoverIntent(dropDownConfig);		
	
	
	
	/*
	 * Initiate fancybox effect for thumbnails
	 */ 
	$("a.lightbox").fancybox({
		'titlePosition'	: 'inside'
	});	




	/*
	 * Options previewers
	 */
	 $("div.previewer").each(function(){
		var img_list = $(this).children("ul");
		var contents = $(img_list).html();
		
		if(contents.length > 0)
		{		
			$(this).prev().find("select").change(function() { 
				var selected_option = $('option:selected', this).attr("value");
				if(selected_option == "Select Option"){ var selected_option = ""; }
				$(img_list).children("li").css('display','none');
				
				if(selected_option.length > 0)
				{
					$(img_list).css('display','block');
					$(img_list).children("li."+selected_option).css('display','block');
				}
				else
				{
					$(img_list).css('display','none');								
				}
				
			});
		}

	 });
	 
	 
	 	/*

	 * Initiate fancybox effect for thumbnails

	 */ 

	$("a.zoom").fancybox({
		'autoScale'		:	true,
		'centerOnScroll'	:	true,
		'hideOnOverlayClick'	:	true,
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'		:	'swing',
		'easingOut'		:	'swing',
		'showCloseButton'	:	true,
		'showNavArrows'		:	true,
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'overlayOpacity'	:	'0.5',
		'overlayColor'	:	'#E5008C',
		'titleShow'		:	false


	});

}); // end ready handler

