$(document).ready(function() {
	
	
	/*-------------------------------------------    
	FORMS:
	Add initial value to fields with .filled class
	-------------------------------------------*/
	var filled = $('input.filled');

	if(filled.length > 0){
		for(var i = 0; i < filled.length; i++){


			$(filled[i]).addClass('empty');
			filled[i].initialValue = filled[i].value;

			filled[i].onclick = filled[i].onfocus = function(){
				$(this).removeClass('empty');
				$(this).addClass('filled');
				if(this.value == this.initialValue){
					this.value= '';
				}
			}

			filled[i].onblur = function(){
				if(this.value == this.initialValue || this.value == ''){
					$(this).addClass('empty');
					$(this).removeClass('filled');
					this.value = this.initialValue;
				}else{
					$(this).addClass('empty');
					$(this).removeClass('filled');
				}
			}
		}
	}
	else
	{
		return; 
	}

	

  $('#slideshow, #slideshow-2').cycle({
		fx: 'fade',
		random:1,
	    speed:1000, 
	    timeout:5000
	});
	
	

/* DROP DOWN MENU
---------------------------------*/

			var timeout    = 100;
			var closetimer = 0;
			var ddmenuitem = 0;

			function jsddm_open()
			{  jsddm_canceltimer();
			   jsddm_close();
			   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

			function jsddm_close()
			{  if(ddmenuitem) ddmenuitem.css ('visibility', 'hidden');}

			function jsddm_timer()
			{  closetimer = window.setTimeout(jsddm_close, timeout);}

			function jsddm_canceltimer()
			{  if(closetimer)
			   {  window.clearTimeout(closetimer);
			      closetimer = null;}}

			$(document).ready(function()
			{  $('#main-menu > li').bind('mouseover', jsddm_open)
			   $('#main-menu > li').bind('mouseout',  jsddm_timer)});


			document.onclick = jsddm_close;


			
			
			
			

/* HOMEPAGE TABS
---------------------------------*/
		$(function () {
			var tabContainers = $('div.tabs > div');
			tabContainers.hide().filter(':first').show();
		
			$('div.tabs ul.tabNavigation a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div.tabs ul.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			}).filter(':first').click();
		});
	
		/*OPEN CLOSE TABS*/
		
		  $("a.close-tabs").click(function () {
				$("div.panel").slideUp("slow");
		  });


		/*OPEN CLOSE FILTER LIST ON DIRECTORY SEARCH*/

		$('.filter-swap').click(function() {
		  $('.filter-list-wrap').toggle('slow', function() {
		    // Animation complete.
		  });
		});


/*
		  $("ul.tabNavigation a").click(function () {
		    if ($("div.panel").is(":hidden")) {
				$("div.panel").slideDown("slow");
			else {$("div.panel").slideUp("slow");}
		  });

*/


/*-------------------------------------------    
LOAD FONTS BEFORE PAGE OR WAIT 3 SECONDS
-------------------------------------------*/


		(function(){
		  // if firefox 3.5+, hide content till load (or 3 seconds) to prevent FOUT
		  var d = document, e = d.documentElement, s = d.createElement('style');
		  if (e.style.MozTransform === ''){ // gecko 1.9.1 inference
		    s.textContent = 'body{visibility:hidden}';
		    e.firstChild.appendChild(s);
		    function f(){ s.parentNode && s.parentNode.removeChild(s); }
		    addEventListener('load',f,false);
		    setTimeout(f,3000); 
		  }
		})();


/*-------------------------------------------    
DATE PICKER
-------------------------------------------*/


		$("#datepicker-to, #datepicker-from").datepicker({
			showOn: 'both',
			buttonImage: 'http://www.takeart.org/dashboard/templates/js/images/calendar.gif',
			buttonImageOnly: 'false',
			dateFormat: "yy-mm-dd"
			
		});


/*-------------------------------------------    
ADD PRINT BUTTON
-------------------------------------------*/

		
		 $('ul.share-btn, ul.share-btn-small').prepend('<li><a href="#" class="share-print" title="Click to print page">Print</a></li>');
			 $('ul.share-btn li a.share-print, ul.share-btn-small li a.share-print').click(function() {
				  window.print();
				  return false;
		 });
		
		

/*-------------------------------------------    
JCAROUSEL
-------------------------------------------*/		
		
		function mycarousel_initCallback(carousel) {
		    jQuery('.jcarousel-control a').bind('click', function() {
		        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		        return false;
		    });
		
		    jQuery('.jcarousel-scroll select').bind('change', function() {
		        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
		        return false;
		    });
		
		    jQuery('#mycarousel-next').bind('click', function() {
		        carousel.next();
		        return false;
		    });
		
		    jQuery('#mycarousel-prev').bind('click', function() {
		        carousel.prev();
		        return false;
		    });
		};
		
		// Ride the carousel...
		jQuery(document).ready(function() {
		    jQuery("#mycarousel").jcarousel({
		        scroll: 1,
		        initCallback: mycarousel_initCallback,
		        // This tells jCarousel NOT to autobuild prev/next buttons
		        buttonNextHTML: null,
		        buttonPrevHTML: null
		    });
		});
		
		
		

	
		
		function events_carousel_initCallback(carousel) {
		    jQuery('.jcarousel-control a').bind('click', function() {
		        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		        return false;
		    });
		
		    jQuery('.jcarousel-scroll select').bind('change', function() {
		        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
		        return false;
		    });
		
		    jQuery('#events-carousel-next').bind('click', function() {
		        carousel.next();
		        return false;
		    });
		
		    jQuery('#events-carousel-prev').bind('click', function() {
		        carousel.prev();
		        return false;
		    });
		};
		
		
		// Ride the carousel...again, for the front page though this time, yay.
		jQuery(document).ready(function() {
		    jQuery("#events-carousel").jcarousel({
		        scroll: 6,
		        vertical: true,
		        initCallback: events_carousel_initCallback,
		        // This tells jCarousel NOT to autobuild prev/next buttons
		        buttonNextHTML: null,
		        buttonPrevHTML: null
		    });
		});

			
/* ENDS
---------------------------------*/
			

});
