﻿
//nav
$(document).ready(function () {
    $(".nav_cat").hover(
		function () {
		    navHighlight( $(this), true );
		},
		function () {
		    navHighlight($(this), false);
		});
});

function navHighlight(navObj, on) {
    var rep1 = (on) ? "_base" : "_hover";
    var rep2 = (on) ? "_hover" : "_base";
    var imageSrc = $(navObj).find("img").attr("src");
    var newSrc = imageSrc.replace(rep1, rep2);
    $(navObj).find("img").attr({ src: "" + newSrc });
}

//tabs
function showTab(i) {
    //hide all
    $(".tab_nav li").removeClass("at");
    $(".tab_contents div").hide();
    //show curr
    $("#tab_nav" + i).addClass("at");
    $("#tab_content" + i).show();
    return false;
}

//outside links
$(document).ready(function () { fixLinks('body') });
function fixLinks(root) {
    var myhost = location.protocol + '//' + location.host;
    $(root).find('a[href^=http]').not('[href^=' + myhost + ']').each(function () {
        var $this = $(this);
        //youtube:
        if ($this.attr("href").indexOf("youtube.com/watch") != -1) {
            var match = this.href.match("[\\?&]v=([^&#]*)");
            if (match.length > 1) {
                var vid = match[1];
                popinVideo($this, 'youtube', vid);
            }
        }
        //vimeo:
        if ($this.attr("href").indexOf("vimeo.com/") != -1) {
            var vimeoID = $this.attr("href").substr($this.attr("href").indexOf(".com/") + 5);
            popinVideo($this, 'vimeo', vimeoID);
        }
        this.target = (this.target) ? this.target : '_blank';
    });
    $('a[target]').not('.youtube').addClass('external');

    //mp3s
    $(root).find('a[href*=.mp3]').each(function () {
        popinAudio($(this));
    });
}

function popinAudio($this) {
    var id = $this.attr('id');
    var appendHTML = '<div id="a_' + id + '" class="hidden"><div id="clip_' + id + '" style="clear:both;">' + $this.text() + '<br /><div style="margin:5px 0; height:27px; display:block;"><embed type="application/x-shockwave-flash" flashvars="audioUrl=' + $this.attr('href') + '" src="http://www.google.com/reader/ui/3523697345-audio-player.swf" width="400" height="27" quality="best" bgcolor="#ffffff" /></div><br /></div></div>';
    $('body').append(appendHTML);
    $this.colorbox({
        height: 120, inline: true, href: "#clip_" + id
    });
}

function popinVideo($this, site, vidID) {
    //vimeo or youtube?
    var thumbImg = (site == "vimeo") ? "/images/vimeo_widget.jpg" : "http://img.youtube.com/vi/" + vidID + "/2.jpg";
    var swfSrc = (site == "vimeo") ? "http://vimeo.com/moogaloop.swf?clip_id=" + vidID + "&server=vimeo.com&autoplay=1" : "http://www.youtube.com/v/" + vidID + "&hl=en&fs=0&rel=0&autoplay=1";

    if (!$this.parent().hasClass("feature_box")) {
        $this.prepend($('<img src="' + thumbImg + '" alt="Watch video" class="videoThumb" />'));
    }
    $('body').append('<div id="v_' + vidID + '" class="hidden"><div id="' + vidID + '"><div id="swf_' + vidID + '"></div></div></div>');
    $this.colorbox({
        width: 582, height: 396, inline: true, resize: false, href: "#" + vidID
    },
		function () {
		    swfobject.embedSWF(
				swfSrc,
				"swf_" + vidID, /* div id */
				560, 340, /* w,h */
				"8.0.0", /* flash version */
				false, /* no express install */
				{}, /* flashvars */
				{allowFullScreen: true, play: true, allowscriptaccess: true }, /* params */
				{} /* attributes */
			);
			$('#' + vidID).show();
		}
	);
}

function enewsSignup( url ) {
    var newWin = window.open(url, 'patron_signup', 'height=500,width=640,scrollBars=1,resizable=0');
    newWin.focus();
    return false;
}

$(document).ready(function () {
	$("a[target=_seatmap]").click(function () { 
		$(this).colorbox() });
});

// forms
// <input type="button" onclick="submitForm(this)" ... />
function submitForm(btn) {
	if (!btn || !btn.nodeName) {
		btn = this;
	}
	if (typeof (Page_ClientValidate) != 'function' || Page_ClientValidate('')) {
		if (!btn.hasBeenClicked) {
			btn.value = "Processing..."
			btn.className = 'buttonClicked';
			btn.blur();
			btn.hasBeenClicked = true;
			return true;
		}
		btn.disabled = true;
		return false;
	}
}

$(document).ready(function () {
	$(".disableOnClick").click(submitForm);
});

// icon filter
function filter(what, title, year) {
    $('.production').removeClass('productionDisabled');
    if (typeof (what) == "object" && what.length) {
        what = $.datepick.formatDate(what[0]);
        title = what;
        for (var i in prods) {
            if ($.inArray(what, prods[i]) == -1) {//we should hide the ones that arent on that date
                $('#prod' + i).addClass('productionDisabled');
            }
        }
        $('.resetFilterButton').show();
    }
    else if (typeof (what) == "number" && year) {
        $('.production').addClass('productionDisabled');
        var ds = new Date(year, what - 1); //date start
        var de = new Date(year, what); //date end
        title = ds.toLocaleString();
        title = title.split(" ");
        title = title[1];
        for (var i in prods) {
            for (var x in prods[i]) {
                var pd = new Date(prods[i][x]); //performance date
                if (pd > ds && pd < de) $('#prod' + i).removeClass('productionDisabled');
            }
        }
        $('.resetFilterButton').show();
    }
    else if (typeof (what) == "string") {
        if (typeof datepick == "function") $('#calendar').datepick('setDate', null);
        $('.production').not('.icon_' + what).addClass('productionDisabled');
        $('.resetFilterButton').show();
    }
    else {
        if (typeof datepick == "function") $('#calendar').datepick('setDate', null);
        $('.resetFilterButton').hide();
    }
    if (title) {
        $('#upcoming_shows_filter_display').show();
        $('#filter_title').html(unescape(title));
    }
    else {
        $('#upcoming_shows_filter_display').hide();
    }
    return false;
}

//photo gallery constructor
GalleryImg = function (nodeID, parentID, src, thumb, caption, credit, group, moreLink) {
    this.nodeID = nodeID;
    this.parentID = parentID;
    this.src = src.replace('’','\'');
    this.thumb = thumb.replace('’', '\'');
    this.caption = caption.replace('’', '\'');
    this.credit = credit.replace('’', '\'');
    this.group = group;
    this.moreLink = moreLink;
    GalleryImg.all[GalleryImg.all.length] = this;
}
GalleryImg.all = new Array();

if ($.datepick) {
	$.datepick.setDefaults({
		prevText: '<img src="/Images/calendar_prev.gif">',
		nextText: '<img src="/Images/calendar_next.gif">'
	});
}

