$(document).ready(function() {

	$('a[id="christmas_1944"]').click(function(){
		$(".christmas_1944").show();	  
	}, function(){	
	});
		
	$('div[class="bronze"]').click(function(){
		$("#silver, #gold, #platinum, #steel").hide();
		$("#bronze").show();  
	}, function(){	
	}); 

	$('div[class="silver"]').click(function(){
		$("#bronze, #gold, #platinum, #steel").hide();
		$("#silver").show();	  
	}, function(){
	}); 

	$('div[class="gold"]').click(function(){
		$("#bronze, #silver, #platinum, #steel").hide();
		$("#gold").show();	  
	}, function(){
	}); 
	
	$('div[class="platinum"]').click(function(){
		$("#bronze, #silver, #gold, #steel").hide();
		$("#platinum").show();	  
	}, function(){
	}); 

	$('div[class="steel"]').click(function(){
		$("#bronze, #silver, #gold, #platinum").hide();
		$("#steel").show();	  
	}, function(){
	}); 
				
	  $(".gallery").click(function () {
		   var image = $(this).attr("id");
		   $("#show_image").replaceWith('<div id="show_image"><img src="http://www.artsquest.org/images/galleries/ff4.1.2011/' + image + '"></div>');	
	  });


	  $(".gallery2").click(function () {
		   var image = $(this).attr("id");
		   $("#show_image").replaceWith('<div id="show_image"><img src="http://www.artsquest.org/images/markets/jpg/' + image + '"></div>');	
	  });
	
	  $(".gallery3").click(function () {
		   var image = $(this).attr("id");
		   $("#show_image").replaceWith('<div id="show_image"><img src="http://www.artsquest.org/images/galleries/mfc-5.1.2011/' + image + '"></div>');	
	  });

	  $(".gallery4").click(function () {
		   var image = $(this).attr("id");
		   $("#show_image").replaceWith('<div id="show_image"  style="margin-left: 60px;"><img src="http://www.artsquest.org/images/galleries/mfc-4.30.2011/' + image + '"></div>');	
	  });

	  $(".gallery5").click(function () {
		   var image = $(this).attr("id");
		   $("#show_image").replaceWith('<div id="show_image"  style="margin-left: 60px;"><img src="http://www.artsquest.org/images/galleries/farmersmarket/' + image + '"></div>');	
	  });

	  $(".gallery6").click(function () {
		   var image = $(this).attr("id");
		   $("#show_image").replaceWith('<div id="show_image"  style="margin-left: 60px;"><img src="http://www.artsquest.org/images/galleries/massensemble/' + image + '"></div>');	
	  });
	  	  	  	    
/******************************************************/
		
	$("#datepicker").datepicker();

	  $(".prev").click(function () {
		  var val = $("#prev").val();	
		  switchImage(val);			   
	  });
	  
	  $(".next").click(function () {
		  var val = $("#next").val();	
		  switchImage(val);			   
	  });

	  $(".fc_prev").click(function () {
		  var val = $("#fc_prev").val();	
		  fc_switchImage(val);			   
	  });
	  
	  $(".fc_next").click(function () {
		  var val = $("#fc_next").val();	
		  fc_switchImage(val);			   
	  });

	//$(document).on("click", "a.cal_prev", function(){ alert("Goodbye!"); }); 
	
	
	$(document).on("click", ".cal_prev", function(){ 
		var val = $("#cal_prev").val();	
		var string = "&cal_date=" + val;
		$.ajax({
			type: "POST",
			url: "http://www.artsquest.org/includes/calendar.php",
			data: string,
			success: function(html){
				$("#calendar").replaceWith(html);
				$("#venue, #artist, #category").val("");
				$("#results").replaceWith('<div id="results"></div>');
			}
		});	
		
	});
	
	
/*	
	$(".cal_prev").on('click', function(event) { 
		var val = $("#cal_prev").val();	
		var string = "&cal_date=" + val;
		$.ajax({
			type: "POST",
			url: "http://www.artsquest.org/includes/calendar.php",
			data: string,
			success: function(html){
				$("#calendar").replaceWith(html);
				$("#venue, #artist, #category").val("");
				$("#results").replaceWith('<div id="results"></div>');
			}
		});	
	}); */

	$(document).on("click", ".cal_next", function(){ 
	//$(".cal_next").on('click', function(event) { 
		var val = $("#cal_next").val();	
		var string = "&cal_date=" + val;
		$.ajax({
			type: "POST",
			url: "http://www.artsquest.org/includes/calendar.php",
			data: string,
			success: function(html){
				$("#calendar").replaceWith(html);
				$("#venue, #artist, #category").val("");
				$("#results").replaceWith('<div id="results"></div>');
			}
		});	
	});	 

	$(".ff").hover(function(){
		$(this).addClass('ff_hover');				  
	}, function(){
		$(this).removeClass('ff_hover');
	}); 
	

	$(".rr_button").hover(function(){
		$(this).addClass('hover');				  
	}, function(){
		$(this).removeClass('hover');
	}); 
	
	$(".film_dropdown").on('change', function(event) { 
		var val = $(this).val();	
		var string = "&film_date=" + val;
		$.ajax({
			type: "POST",
			url: "http://www.artsquest.org/ajax/film_dates.php",
			data: string,
			success: function(html){
				$("#film_results").replaceWith(html);
			}
		});	
	}); 
	
});

/*
	$("#nav_festivals").hover(function(){
		$("#m2").css('visibility', 'visible');
		$("#m2").show();				  
	}, function(){
		
	}); 
	*/
	
var timeout__2    = 500;
var closetimer__2 = 0;
var ddmenuitem__2 = 0;

function jsddm_open() {  
	jsddm_canceltimer();
    jsddm_close();
    ddmenuitem__2 = $(this).find('ul').css('visibility', 'visible');
}

function jsddm_close() {  
	if(ddmenuitem__2) 
		ddmenuitem__2.css('visibility', 'hidden');
}

function jsddm_timer() {  
	closetimer__2 = window.setTimeout(jsddm_close, timeout__2);
}

function jsddm_canceltimer(){  
	if(closetimer__2) {  
		window.clearTimeout(closetimer__2);
      	closetimer__2 = null;
	}
}

$(document).ready(function() {  
	$('#jsddm > li').bind('mouseover', jsddm_open)
   	$('#jsddm > li').bind('mouseout',  jsddm_timer)
});

document.onclick = jsddm_close;



var rotatingLinks = new Array("http://www.airproducts.com/", "http://www.butz.com/company.htm", "http://www.aramark.com/", "http://www.bankobeverage.com/", "https://www.capbluecross.com/", "http://www.xmascity.com/", "http://www.lehighvalleycoke.com/", "", "http://www.thehartford.com/Auto-Insurance-Investments-Retirement", "http://www.justborn.com/", "http://www.martinguitar.com/", "https://www.pnc.com/", "https://www.pasands.com/pennsylvania-casino/hotel/", "http://www.sectv.com/", "http://www.yuengling.com"); 
var rotatingImages = new Array("http://www.artsquest.org/images/logos/AirProductsLogo.jpg", "http://www.artsquest.org/images/logos/AlvinButzLogo.jpg", "http://www.artsquest.org/images/logos/AramarkLogo.jpg", "http://www.artsquest.org/images/logos/BankoLogo.jpg", "http://www.artsquest.org/images/logos/CapitalBlueLogo.jpg", "http://www.artsquest.org/images/logos/christmascity.jpg", "http://www.artsquest.org/images/logos/Coke.jpg", "http://www.artsquest.org/images/logos/FowlerPenaLogo.jpg", "http://www.artsquest.org/images/sponsors/hartford.jpg",  "http://www.artsquest.org/images/logos/JustBornLogo.jpg", "http://www.artsquest.org/images/logos/MartinGuitarLogo.jpg", "http://www.artsquest.org/images/logos/PNCLogo.jpg", "http://www.artsquest.org/images/logos/SandsLogo.jpg", "http://www.artsquest.org/images/logos/ServiceElectricLogo.jpg", "http://www.artsquest.org/images/logos/YuenglingLogo.jpg");

imageCount = rotatingImages.length;
firstTime = true;
duration = "10"; //seconds

function rotateImage(){
	if (document.getElementById('rotatingImage').complete || firstTime){
		if (firstTime) {
			thisImage = Math.floor((Math.random() * imageCount));
			firstTime = false;
		}
		else{
			thisImage++
			if (thisImage == imageCount) {
				thisImage = 0;
			}
		}
		document.getElementById('rotatingLink').href = rotatingLinks[thisImage];
		document.getElementById('rotatingImage').src = rotatingImages[thisImage];
		setTimeout("rotateImage()", duration * 1000);
	}
}
function switchImage(value){
	if (document.getElementById('rotatingImage').complete){
		document.getElementById('rotatingLink').href = rotatingLinks[value];
		document.getElementById('rotatingImage').src = rotatingImages[value];
		setTimeout("rotateImage()", duration * 1000);
	}
}

	
/*var images = new Array("glassblowing.jpg", "soup.jpg", "tv.jpg")
var imagelinks = new Array("http://www.artsquest.org/arts/classes.html", "http://www.artsquest.org/soup/", "http://www.steelstackslive.org/")

function swapImage() {			
	var ry = Math.floor(Math.random() * images.length)
	document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img id="rotatingImage" src="http://www.artsquest.org/images/rightrail/'+images[ry]+'" border="0" width="246" height="70"></a>')
}*/

function resizeIframe() {
	
	var FramePageHeight = framePage.scrollHeight + 10; 
	var id = $("#framePage").attr("id");
	var source = $("#framePage").attr("src");

	$('#framePage').attr({
		height: FramePageHeight
	});

	var oParentDoc = $(parent.document).find("#framePage");
	
	$(oParentDoc).addClass("loading");
} 


function slider() {
 	$(document).ready(function(){
		$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
	});	
}
