/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.1, 11.09.2007
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(s($){3.1s.1k=s(j){j=3.1a({12:\'1m.1j\'},j);8 k=(n.P=="r 10 Z"&&U(n.v)==4&&n.v.E("14 5.5")!=-1);8 l=(n.P=="r 10 Z"&&U(n.v)==4&&n.v.E("14 6.0")!=-1);o(3.17.16&&(k||l)){3(2).L("1r[@m$=.M]").z(s(){3(2).7(\'q\',3(2).q());3(2).7(\'p\',3(2).p());8 a=\'\';8 b=\'\';8 c=(3(2).7(\'K\'))?\'K="\'+3(2).7(\'K\')+\'" \':\'\';8 d=(3(2).7(\'A\'))?\'A="\'+3(2).7(\'A\')+\'" \':\'\';8 e=(3(2).7(\'C\'))?\'C="\'+3(2).7(\'C\')+\'" \':\'\';8 f=(3(2).7(\'B\'))?\'B="\'+3(2).7(\'B\')+\'" \':\'\';8 g=(3(2).7(\'R\'))?\'1d:\'+3(2).7(\'R\')+\';\':\'\';8 h=(3(2).1c().7(\'1b\'))?\'19:18;\':\'\';o(2.9.y){a+=\'y:\'+2.9.y+\';\';2.9.y=\'\'}o(2.9.t){a+=\'t:\'+2.9.t+\';\';2.9.t=\'\'}o(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}8 i=(2.9.15);b+=\'<x \'+c+d+e+f;b+=\'9="13:11;1q-1p:1o-1n;O:W-V;N:1l;\'+g+h;b+=\'q:\'+3(2).q()+\'u;\'+\'p:\'+3(2).p()+\'u;\';b+=\'J:I:H.r.G\'+\'(m=\\\'\'+3(2).7(\'m\')+\'\\\', D=\\\'F\\\');\';b+=i+\'"></x>\';o(a!=\'\'){b=\'<x 9="13:11;O:W-V;\'+a+h+\'q:\'+3(2).q()+\'u;\'+\'p:\'+3(2).p()+\'u;\'+\'">\'+b+\'</x>\'}3(2).1i();3(2).1h(b)});3(2).L("*").z(s(){8 a=3(2).T(\'N-S\');o(a.E(".M")!=-1){8 b=a.X(\'1g("\')[1].X(\'")\')[0];3(2).T(\'N-S\',\'1f\');3(2).Q(0).Y.J="I:H.r.G(m=\'"+b+"\',D=\'F\')"}});3(2).L("1e[@m$=.M]").z(s(){8 a=3(2).7(\'m\');3(2).Q(0).Y.J=\'I:H.r.G\'+\'(m=\\\'\'+a+\'\\\', D=\\\'F\\\');\';3(2).7(\'m\',j.12)})}1t 3}})(3);',62,92,'||this|jQuery||||attr|var|style|||||||||||||src|navigator|if|height|width|Microsoft|function|padding|px|appVersion|margin|span|border|each|class|alt|title|sizingMethod|indexOf|scale|AlphaImageLoader|DXImageTransform|progid|filter|id|find|png|background|display|appName|get|align|image|css|parseInt|block|inline|split|runtimeStyle|Explorer|Internet|relative|blankgif|position|MSIE|cssText|msie|browser|hand|cursor|extend|href|parent|float|input|none|url|after|hide|gif|pngFix|transparent|blank|line|pre|space|white|img|fn|return'.split('|'),0,{}))
/* end pngfix */


var menuWaitTime = 400;
var citiesTimeout = 0;
var showsTimeout = 0;
var dropdownItemsCount = 0;
var showsLevel2_open = false;
var citiesLevel2_open = false;
var currentImage = 0;
var imagesCount = 0;

$(document).ready(function(){
	
	//png24 fix for all images
	$(document).pngFix();
	
	//ie6 fix for logo clicks (transparency issue with png fix?)
	$("#logo, #footer_logo, .guide_button, .guide_button_big").css("cursor","pointer");
	
	$("#logo").click(function(){
		window.location = $("#logo a").attr("href");
	});
	
	$("#footer_logo").click(function(){
		window.location = $("#footer_logo a").attr("href");
	});
	
	$(".guide_button").click(function(){
		window.location = $(".guide_button a").attr("href");
	});

	$(".guide_button_big").click(function(){
		window.location = $(".guide_button_big a").attr("href");
	});

	// style buttons and certain elements for opacity mouseOver
	$(".submitButton, #searchSubmit, #nav .level1, #pagination_buttons a").mouseover(function(){
		$(this).css("opacity", .85);
	}).mouseout(function(){
		$(this).css("opacity", 1);
	});
	
	
	// style links with underline on mouseOver
	$("a").mouseover(function(){
		$(this).css("text-decoration", "underline");
	}).mouseout(function(){
		$(this).css("text-decoration", "none");
	});
	
	// un-style certain elements with underline
	$("#nav_cityguide a, .dropdown_item, #pagination_buttons a, .filter_box_select a").mouseover(function(){
		$(this).css("text-decoration", "none");
	});

	// fill dropdowns with proper info
	initDropdowns();
	
	// setup dropdown events/animations
	dropdownBehavior();

	
	setFlags();
	
	if ($("#slideshow").html()) {
		$(".large_ul").children("li").each(function(){
			imagesCount++;
		});
		$(".lg_image_holder").css("width",imagesCount*640);
		$(".lg_image_holder").fadeIn();
	}
	
});


function documentLoaded() {
	// fix buggy addthis
	//$("#searchField").val(""); //reset search field, sometimes shows label from addthis
	$("#addthis_dropdown15").removeAttr("onmouseout");
	$("#addthis_dropdown15").children("table").children("tbody").children("tr").children("td").next().click(function() { addthis_close(); });
	$("#addthis_dropdown15").children("table").children("tbody").children("tr").children("td").next().css("cursor","pointer");

	// stylize email form
	$("#at_email").children("table").children("tbody").children("tr").children("td").css("padding",3);
	$("#at_from, #at_to").css("width",230);
	$("#at_msg").css("width",234);
	$("#at_msg").css("height",80);
	$("#at_msg").attr("wrap","soft");
	
	if ($("#slideshow").html()) { setupSlideshow(); }
}

function setupSlideshow() {
	
	$(".thumbs ul li").mouseover(function(){
		$(this).css("opacity", .85);
	}).mouseout(function(){
		$(this).css("opacity", 1);
	});
	
	var thumbsWidth = 0;
	$(".thumbs_ul").children("li").each(function(){
		thumbsWidth += ($(this).children("img").outerWidth() + 6);
		$(this).mouseover(function(){$(this).css({cursor:"hand",cursor:"pointer"})});
		$(this).bind("click", function(){
			$(".lg_image_holder").animate({left: checkLeftRightArrows(parseInt($(this).children("img").attr("rel"))-currentImage)*-640});
			//currentImage =  $(this).children("img").attr("rel");
			//checkLeftRightArrows(currentImage);
			updateCurrent(this);
		});
	});
	$(".thumbs_holder").css("width",thumbsWidth+6);
	
	// if needed, add more/back
	if (thumbsWidth>560) {
		deactivateBtn("#thumb_back");
		$("#thumb_back").fadeIn();
		$("#thumb_more").fadeIn();
	}

	$("#thumb_more").bind("click", function(){
		var newLeft = parseInt($(".thumbs_holder").css("left")) - 560;
		if (newLeft<= (-thumbsWidth+560)) { newLeft = -thumbsWidth+560; deactivateBtn("#thumb_more");}
		$(".thumbs_holder").animate({left: newLeft});
		activateBtn("#thumb_back");
		return false;
	});
	
	$("#thumb_back").bind("click", function(){
		var newLeft = parseInt($(".thumbs_holder").css("left")) + 560;
		if (newLeft>=0) { newLeft = 0; deactivateBtn("#thumb_back");}
		$(".thumbs_holder").animate({left: newLeft});
		activateBtn("#thumb_more");
		return false;
	});	
	
	// add next/prev arrows
	if (imagesCount>1)
	{
		$("#prev_photo_btn").
			fadeIn().fadeTo("normal", .01).
			bind("click", function(){
				$(".lg_image_holder").animate({left: checkLeftRightArrows(-1)*-640});
				updateCurrent($(".thumbs_ul").children("li").filter(function(index) {return $("img", this).attr("rel") == currentImage;}));
				return false;
			}).
			bind("mouseover", function(){
				$(this).css("background-color", "#eee");	   
			}).
			bind("mouseout", function(){
				$(this).css("background-color", "#fff");	   
			});
		$("#next_photo_btn").
			fadeIn().fadeTo("normal", .7).
			bind("click", function(){
				$(".lg_image_holder").animate({left: checkLeftRightArrows(1)*-640});
				updateCurrent($(".thumbs_ul").children("li").filter(function(index) {return $("img", this).attr("rel") == currentImage;}));
				return false;
			}).
			bind("mouseover", function(){
				$(this).css("background-color", "#eee");	   
			}).
			bind("mouseout", function(){
				$(this).css("background-color", "#fff");	   
			});
	}
	
}

function checkLeftRightArrows(currentImageMod) {
	if (((currentImage+currentImageMod)!=(imagesCount)) && ((currentImage+currentImageMod)!=(-1))) {
		currentImage = currentImage + currentImageMod;
	}
	if ((currentImage)==(imagesCount-1)) {
		$("#next_photo_btn").fadeTo("normal", .01).css({cursor:"default"});
	}
	if (currentImage==0) {
		$("#prev_photo_btn").fadeTo("normal", .01).css({cursor:"default"});
	}
	if (currentImage>=1) {
		$("#prev_photo_btn").fadeTo("normal",.7).css({cursor:"hand", cursor:"pointer"});
	}
	if (currentImage<=imagesCount-2) {
		$("#next_photo_btn").fadeTo("normal",.7).css({cursor:"hand", cursor:"pointer"});
	}	
	//$("#lxmailEmail").val(currentImage);
	return currentImage;
}


function updateCurrent(new_li) {
	$(".thumbs_ul").children("li").each(function(){ $(this).removeClass("color2_fg"); });
	$(new_li).addClass("color2_fg");
}

function deactivateBtn(d) {	
	$(d).css("opacity",.4);
	$(d).mouseover(function(){
		$(this).css("text-decoration", "none");
	})
}

function activateBtn(d) {	
	$(d).css("opacity",1);
	$(d).mouseover(function(){
		$(this).css("text-decoration", "underline");
	})
}


function addthis_email(loc) {
	$("#addthis_dropdown15").css("width",310);
	addthis_open(loc, 'email', addURL, addTitle);
	return false;
}


function addthis_share(loc) {
	$("#addthis_dropdown15").css("width",230);
	addthis_open(loc, '', addURL, addTitle);
	return false;
}


function initDropdowns() {
	
	// populate menu from ul
	$('#dropdown_cities_ul').html( $('#nav_cities').children("ul").html() );
	$('#dropdown_shows_ul').html( $('#nav_shows').children("ul").html() );
	
	// update to same heights, based on tallest
	var newHeight = 0;
	var cityHeight = $("#dropdown_cities").height();
	var showHeight = $("#dropdown_shows").height();
	if (cityHeight > showHeight) {
		newHeight = cityHeight;
		dropdownItemsCount =  $("#dropdown_cities").children("ul").children("li").length;
	} else { 
		newHeight = showHeight;
		dropdownItemsCount = $("#dropdown_shows").children("ul").children("li").length;
	}
	$(".dropdown").css("height", newHeight);

}



function dropdownBehavior() {

	// activate the CITIES dropdown
	//
	$("#nav_cities").mouseover(function(){
		//clearTimeout(showsTimeout);
		clearTimeout(citiesTimeout);
		$("#dropdown_cities_level2").hide();
		$("#dropdown_cities_level2").css("marginLeft",149);
		$("#dropdown_shows").hide();
		showCities();
		removeShowsHovers();
		citiesLevel2_open = false;
	}).mouseout(function(){
		clearTimeout(citiesTimeout);
		citiesTimeout = setTimeout(hideCities, menuWaitTime);
	});
	
	
	$("#dropdown_cities, #dropdown_shows_level2").mouseover(function(){
		$("#dropdown_shows").hide();
		clearTimeout(citiesTimeout);
	}).mouseout(function(){
		clearTimeout(citiesTimeout);
		citiesTimeout = setTimeout(hideCities, menuWaitTime);
	});	
	
	
	$("#dropdown_cities li").mouseover(function(){
		//loop twice - weird instance of not working in IE otherwise
		for (z=0;z<2;z++)
		{
			// style hover
			removeCitiesHovers();
			$(this).children("a").addClass("dropdown_hover");
			
			// update level2 with related shows
			$("#dropdown_shows_ul_level2").html($(this).children("ul").html());
		
			// move to appropriate place in list
			currentIndex = parseInt($(this).children("a").attr("rel"))-1;
			showsLength = $(this).children("ul").children("li").length;
			if ((currentIndex + showsLength) > dropdownItemsCount) { currentIndex = currentIndex - showsLength + 1; }
			for (i=0; i<currentIndex; i++) { $("#dropdown_shows_ul_level2").prepend("<li><a><span>&nbsp;</span></a></li>"); }
			
			// mouseovers styles for level2
			$("#dropdown_shows_ul_level2 li a").mouseover(function(){
				//IE PROBLEMS
				//doesnt recognize anything first time
				$(this).addClass("dropdown_hover");
			}).mouseout(function(){
				$(this).removeClass("dropdown_hover");	
			});	
			
			// if closed, open level2 panel
			if (!showsLevel2_open) {
				showsLevel2_open = true;
				$("#dropdown_shows_level2").animate({width:"show"},"fast");
			}
		}
	});


	// activate the SHOWS dropdown
	//
	$("#nav_shows").mouseover(function(){
		clearTimeout(showsTimeout);
		//clearTimeout(citiesTimeout);
		showShows();
		$("#dropdown_shows_level2").hide();
		$("#dropdown_cities").hide();
		removeCitiesHovers();
		showsLevel2_open = false;
	}).mouseout(function(){
		clearTimeout(showsTimeout);
		showsTimeout = setTimeout(hideShows, menuWaitTime);
	});
	
	
	$("#dropdown_shows, #dropdown_cities_level2").mouseover(function(){
		$("#dropdown_cities").hide();
		clearTimeout(showsTimeout);
	}).mouseout(function(){
		clearTimeout(showsTimeout);
		showsTimeout = setTimeout(hideShows, menuWaitTime);
	});
	
	
	$("#dropdown_shows li").mouseover(function(){	
		//loop twice - weird instance of not working in IE otherwise
		for (z=0;z<2;z++)
		{
			// add style for hover
			removeShowsHovers();
			$(this).children("a").addClass("dropdown_hover");
	
			// update level2 with proper cities
			$("#dropdown_cities_ul_level2").html($(this).children("ul").html());
	
			// move to appropriate place in list
			currentIndex = parseInt($(this).children("a").attr("rel"))-1;
			showsLength = $(this).children("ul").children("li").length;
			if ((currentIndex + showsLength) > dropdownItemsCount) { currentIndex = currentIndex - showsLength + 1; }
			for (i=0; i<currentIndex; i++) { $("#dropdown_cities_ul_level2").prepend("<li><a><span>&nbsp;</span></a></li>"); }
	
			// mouseovers for level2
			$("#dropdown_cities_ul_level2 li a").mouseover(function(){
				$(this).addClass("dropdown_hover");
			}).mouseout(function(){
				$(this).removeClass("dropdown_hover");	
			});
		
			// style dropdown to right align instead of left
			//$("#dropdown_cities_level2").css("text-align","right");
			//$("#dropdown_cities_ul_level2 li a span").css("padding-left",0);
	
			// if closed, open panel
			if (!citiesLevel2_open) {
				citiesLevel2_open = true;
				$("#dropdown_cities_level2").animate({width:"show", marginLeft:9},"fast");
			}
		}
	});
}



function removeCitiesHovers() {
	$("#dropdown_cities_ul").children().each(function(){
		$(this).children("a").removeClass("dropdown_hover");
	});
}



function removeShowsHovers() {
	$("#dropdown_shows_ul").children().each(function(){
		$(this).children("a").removeClass("dropdown_hover");
	});
}



function showCities() {
	clearTimeout(citiesTimeout);
	$("#dropdown_cities").slideDown("fast");
}



function hideCities() {
	clearTimeout(citiesTimeout);
	$("#dropdown_cities").slideUp("fast");
	$("#dropdown_shows_level2").animate({width:"hide", height:"hide"},"fast");
	showsLevel2_open = false;
	removeCitiesHovers();
}


function showShows() {
	clearTimeout(showsTimeout);
	$("#dropdown_shows").slideDown("fast");
}


function hideShows() {
	clearTimeout(showsTimeout);
	$("#dropdown_shows").slideUp("fast");
	$("#dropdown_cities_level2").animate({marginLeft:149, width:"hide", height:"hide"},"fast");
	citiesLevel2_open = false;
	removeShowsHovers();
}

var setFlags = function(){
	$('#comments_content .commentFlag').click(function(){
		if(! $(this).attr('rev') ){
			$(this).attr('rev', '1')
			LxtvAjax.flagComment( $(this).attr('rel') );
		}
		
		$(this).children('.msg').removeClass('hide');
		
	});
}

function submitHeaderSearch(){
	$('#header_search').submit();
}


function submit(p_sFormId){
	if($('#'+p_sFormId))
		$('#'+p_sFormId).submit();
}

function clearInput(p_xInputField){//}, defaulttext) {
	//if (thisfield.value == defaulttext) {
		p_xInputField.value = "";
	//}
}





