/*
function checkLocation() {
	if (document.location_form.location.value == "Enter ZIP or City") {
		document.location_form.action = "http://www.fandango.com/";	} 
	else {
			document.location_form.method = "get";
			document.location_form.action = "http://www.fandango.com/redirect.aspx?" }			
}
*/										
function checkLocation() {
	if (document.location_form.location.value == "Enter ZIP or City") {
		document.location_form.action = "http://www.fandango.com/?CJAFFILIATE";	} 
	else {
			document.location_form.action = "http://www.fandango.com/redirect.aspx?" }			
}

function checkKeyword() {
	if (document.keyword_form.q.value == "Enter Movie or Actor") {
		document.keyword_form.q.value = "";
		document.location_form.action = "http://www.fandango.com/GlobalSearch.aspx?"; }
}
	
		var place = 0;
		var panes = 0;
		var num = 0;
		var placesInPane = 4;
		var currPos = -1;
		var infoShowArray = new Array();
		var timeOutArray = new Array();
		var movieHeight = 0;
		var	movieWidth = 564;
		
		$(function() {
				$(".movie-set .movie .image").each(function(i) {
					$(this).hover(function(){
							if(currPos!= i && infoShowArray[currPos]) {
								hideMovieInfo(currPos);
								clearTimeout(timeOutArray[currPos])
							}
							if(!infoShowArray[i]) {
								thisEl = this;
								intentionalMouseOver = setTimeout("showMovieInfo(thisEl,"+i+")", 200);
							} else {
								clearTimeout(timeOutArray[i]);
							}
							
						},function(){
							if(infoShowArray[i]) {
								timeOutArray[i] = setTimeout("hideMovieInfo("+i+")", 800);
							}
							clearTimeout(intentionalMouseOver);
					});
					//determine tallest movie container
					if ($(this).parent().height() > movieHeight) movieHeight = $(this).parent().height();
					
					num++;
				});
				movieHeight += 'px'

				$(".movie-set").height(movieHeight);
				$(".movie").height(movieHeight);
				
				if (num > placesInPane) {
					$("#upcoming").prepend("<div id='prev'><a href='javascript:void(0)'>previous</a></div>");
					$("#prev").click(function(){ 
						 updateMoviePane('-'); 
						 if(infoShowArray[currPos]) {
							 hideMovieInfo(currPos);
							 clearTimeout(timeOutArray[currPos]);
						 }
						 });
					$("#upcoming").prepend("<div id='next'><a href='javascript:void(0)'>next</a></div>");
					$("#next").click(function(){ 
						 updateMoviePane('+'); 
						 if(infoShowArray[currPos]) {
							 hideMovieInfo(currPos);
							 clearTimeout(timeOutArray[currPos]);
						 }
						 });

					$("#next").show();
					
					panes = Math.ceil($(".movie").length / placesInPane);
					$("#upcoming").prepend("<ul id='moviePaneNav'></ul>");
					for(x=0; x<panes; x++) {
						thisID = 'pane' + x;
						$("#moviePaneNav").append("<li><a href='#' id='"+ thisID +"' onclick='updateMoviePane("+ x +"); return false;'>"+ parseInt(x+1) +"</a></li>");
					}
					
					$("#moviePaneNav a:first").addClass('selected');
					$("#moviePaneNav li:first").css('background','none');	
					
				}
				
				$(".movie-info").each(function(t) {
					// add pointer div for graphic
					$(this).append("<div class='pointer'></div>");					
					// move movie-info divs to outermost level
					$(this).appendTo("body");
					$(this).hover(function() {
						clearTimeout(timeOutArray[t]);				   
				   },function() {
					   timeOutArray[t] = setTimeout("hideMovieInfo("+t+")", 500);
				   });
				});
				
				// tab switcher
				$("#top_10 .tabs li a").each(function(i) {
					$(this).click(function() {
						top10Switch(i);
						this.blur();
						return false;
					});
				});

		});

		function showMovieInfo(el, pos) {
			// get location of movie 			
			var offset = {};
			$(el).offset({ scroll: true }, offset);
			// location of movie - location of upcoming div = movie info bubble position;
			currPos = pos;
			currLeft = offset.left+80+"px";
			currTop = offset.top+108+"px";
			currInfo = $(".movie-info").get(pos);
			$(currInfo).top(currTop).left(currLeft).show();	
			infoShowArray[pos] = true;
		}
		function hideMovieInfo(pos) {
			$(currInfo).hide();
			infoShowArray[pos] = false;
		}

		function updateMoviePane(increment) {
			if( typeof(increment) == 'number') {
				place = increment;
			} else if (increment == '+'){
				place++;
			} else if (increment == '-') {
				place--;
			}
			pxNew = movieWidth * place;
			$(".movie-set").animate({ left: -pxNew }, 500, function(){
				updateMoviePaneNav();
			});
		}
		
		function updateMoviePaneNav() {
			if (place == 0) {
				$("#prev").hide();
				$(".movie-set").left('1px');
			} else {
				$("#prev").show();
			}
			
			if (place == panes-1) {
				$("#next").hide();
			} else {
				$("#next").show();
			}
			
			$("#moviePaneNav a").removeClass('selected');
			$("#moviePaneNav a").filter('#pane' + place).addClass('selected');
		}

		function top10Switch(num) {
			if (num == "0") {
				$("#top_10").removeClass().addClass("on-box_office");
			}
			if (num == "1") {
				$("#top_10").removeClass().addClass("on-fan_rated");
			}
			newsHeight = $("#movies").height() - $("#newsletter").height();
			$("#newsletter").css({ top: newsHeight});
		}
		
	
//<script language="Javascript" type="text/javascript" src="http://images.fandango.com/scripts/global.js">
