/* Apply JQuery Cycle to all divs of class imageContainer */
function updateFeastival() {
	$("#feastival #ga_extprice").html("$" + $("#feastival #ga_qty").val() * 200);
	$("#feastival #vip_extprice").html("$" + $("#feastival #vip_qty").val() * 300);
	$("#feastival #subtotal").html("$" +
		($("#feastival #ga_qty").val() * 200 +
		$("#feastival #vip_qty").val() * 300));
}

$(document).ready(function(){
	$(".imageContainer").cycle({
	    fx:    'fade', random:1,
	    speed:  900 ,
		after:     function() {
            $('#caption').html(this.alt);
		}
	 });

	updateFeastival();
	$("#feastival #ga_qty").change(function(){ updateFeastival() });
	$("#feastival #vip_qty").change(function(){ updateFeastival() });

	$("#amountBlank").change(function() { 
		if ($("#amountBlank").val() != "") {
			$("#amountOther").attr("checked","checked");
			$(".dlevel").attr("checked","");
		}
	});
	$("#amountOther").change(function() {
		if ($(this).is(":checked")) {
			$(".dlevel").attr("checked","");
		}
	});
	$(".dlevel").change(function() {
		if ($(this).is(":checked")) {
			$("#amountBlank").val("");	
			$("#amountOther").attr("checked","");
		}
	});

	 nextfest = new Date();
	 /* date --date="2011-09-02 12:00:00" +%s 
	    append 3 zeroes */
	 nextfest.setTime(1347037200000);
                          
	 $(".countdown").countdown({until: nextfest, format: "DHMS"});

 /* Replace search feild background text */

		// on focus
		$('#search-field').focus(function(){
			$('.overlabel').hide();
		});

		// on blur
		$('#search-field').blur(function(){
			var searchValue = $('#search-field').val();
			if (searchValue.length > 1) {
				$('.overlabel').hide();
			}
			else {
				$('.overlabel').show();
			}
		});

		// if there is a value in the search field
		$("#password").ready(function(){
			var searchValue = $('#search-field').val();
			if (searchValue.length > 1) {
				$('.overlabel').hide();
			} else {
				$('#search-field').show();
			}
		});


	function updateFilters(evt) {

		// only supports one "many" list like this.
		var keywordSelector = "";
		var newKeywordSelector = "";
		var manyList = new Array();

                $(".filterBoxDates input").next().removeClass("checked");
		$(".filterBoxDates input:checked").next().addClass("checked");
                
		$(".filterBox, .filterBoxH").each(function(i, box) {
			var checkedKeywords=new Array();
			if (box.id.substring(0,3) == "all") {
				$("#"+ box.id + " input[checked]").each(function(j, keyword){
					checkedKeywords.push(keyword.id);
				})
				//console.log("Valid items must have all of " + checkedKeywords)
				$.each(checkedKeywords, function(k) {
					keywordSelector += "." + checkedKeywords[k];
				})
			} else if (box.id.substring(0,3) == "any") {
				$("#"+ box.id + " input:not([checked])").each(function(j, keyword){
					checkedKeywords.push(keyword.id);
				})
				//console.log("Valid items must have none of " + checkedKeywords);
				$.each(checkedKeywords, function(k) {
					keywordSelector += ":not(." + checkedKeywords[k] + ")";
				})
			} else if (box.id.substring(0,4) == "many") {
				$("#"+ box.id + " input[checked]").each(function(l, keyword){
					manyList.push(keyword.id);
				})
			}
		});

		$.each(manyList, function(m) {
			if (newKeywordSelector.length) {
				newKeywordSelector += ", ";
			}
			newKeywordSelector += "#showList tr." + manyList[m]	+ keywordSelector;
		});
		if (newKeywordSelector.length) {
			keywordSelector = newKeywordSelector;
		} else {
			keywordSelector = "#showList tr" + keywordSelector;
		}
		//console.log(keywordSelector);

		var dateList=new Array();
		var dateSelector = "";
		var newDateSelector = "";
		$(".filterBoxDates").each(function(i, box) {
			$("#"+ box.id + " input[checked]").each(function(l, keyword){
					dateList.push(keyword.id);
			})
		});

		var newDateSelector = "";
		$.each(dateList, function(m) {
			if (newDateSelector.length) {
				newDateSelector += ", ";
			}
			newDateSelector += "#showList tr." + dateList[m] + dateSelector;
		});
		if (newDateSelector.length) {
			dateSelector = newDateSelector;
		} else {
			dateSelector = "#showList tr" + dateSelector;
		}

		$("#showList tr").hide().removeClass("keywordVisible dateVisible");
		$(keywordSelector).addClass("keywordVisible");
		//console.log(dateSelector);
		$(dateSelector).addClass("dateVisible");

	}

	$(".filterBox input, .filterBoxH input, .filterBoxDates input, .filterBoxDates label").click(updateFilters);

	// ie fails to forward event from label to hidden input.
	if ($.browser.msie) {
		$(".filterBoxDates label").click(function(event){
			event.preventDefault();
			$(this).toggleClass("checked");
			$(this).prev().click();
                        $(this).toggleClass('checked');
		});
	}

	$("#filters #showAll").click(function(){
		$("form#filters")[0].reset();
		updateFilters();
	});

	updateFilters();

});



/* Suckerfish Hover Script for IE6, from http://htmldog.com/articles/suckerfish/dropdowns/ */

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);


/* Rotating Home Page Text */

var quote=new Array();
  quote[0]='The Festival is Theater';    /* add as many quotes as you like!*/
  quote[1]='The Festival is Dance';
  quote[2]='The Festival is Music';
  quote[3]='The Festival is 16 Days of Wild Creativity';
  quote[4]='The Festival is Daring Performances';
  quote[5]='The Festival is Local Pioneers';
  quote[6]='The Festival is International Legends';
  quote[7]='The Festival is Philadelphia';
  quote[8]='The Festival is Yours';

var speed=2000;    /*this is the time in milliseconds adjust to suit*/
var q=0;

function showQuote() {

     document.getElementById("quotes").innerHTML=quote[q];
     q++;
if(q==quote.length) {
     q=0;
  }
}
setInterval('showQuote()',speed);

/* Rotating Support Page Text */

var quotes=new Array();
  quotes[0]='to make it YOUR Festival';    /* add as many quotes as you like!*/
  quotes[1]='to save 20% on tickets';
  quotes[2]='to support creation';
  quotes[3]='to support experimentation';
  quotes[4]='to support local artists';
  quotes[5]='to bring world-renowned artists to Philly';
  quotes[6]='to connect with the art';
  quotes[7]='to create vibrant communities';
  quotes[8]='to keep the lights on, the artists fed and the Festival fun';
  quotes[9]='to celebrate the 15th Live Arts Festival &amp; Philly Fringe';
  quotes[10]='to keep making art with us';
  quotes[11]='to be entered to win an All Access Pass';
  

var speed=3000;    /*this is the time in milliseconds adjust to suit*/
var q=0;

function showQuotes() {

     document.getElementById("quotes2").innerHTML=quotes[q];
     q++;
if(q==quotes.length) {
     q=0;
  }
}
setInterval('showQuotes()',speed);


/* Mouseovers for LAB Artists */

oneName = new Image();
oneName.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/choi-name.jpg";
onePhoto = new Image();
onePhoto.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/choi.jpg";

twoName = new Image();
twoName.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/jain-name.jpg";
twoPhoto = new Image();
twoPhoto.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/jain.jpg";

threeName = new Image();
threeName.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/kiley-name.jpg";
threePhoto = new Image();
threePhoto.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/kiley.jpg";

fourName = new Image();
fourName.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/kosoko-name.jpg";
fourPhoto = new Image();
fourPhoto.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/kosoko.jpg";

fiveName = new Image();
fiveName.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/osborne-name.jpg";
fivePhoto = new Image();
fivePhoto.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/osborne.jpg";

sixName = new Image();
sixName.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/ford-name.jpg";
sixPhoto = new Image();
sixPhoto.src = "http://www.livearts-fringe.org/lab/img/fellows/2011/ford.jpg";

/* Hidden Text Blocks */

function unhide(divID) {
 var item = document.getElementById(divID);
 if (item) {
 item.className=(item.className=='hidden')?'unhidden':'hidden';
 }
 }

/* Datepicker */

$(document).ready(function() {
    $(".datepicker").datepicker({
	});
});


