﻿// CSS for Javascript Disabled Features
// Collapsing List
(function() {
	var head = document.getElementsByTagName("head")[0];
	if (head) {
		var scriptStyles = document.createElement("link");
		scriptStyles.rel = "stylesheet";
		scriptStyles.type = "text/css";
		scriptStyles.href = "/css/javascript.css";
		scriptStyles.media = "screen,print";
		head.appendChild(scriptStyles);
	}
} ());

// Collapsing List =============================================
var CollapsingList = {
	Init: function() {
		jQuery(".year-container h2.year").each(function() { jQuery(this).addClass('close'); jQuery(this).html('<span class="ind closed">+</span><span class="ind opened">-</span>' + jQuery(this).html()); });
		jQuery(".year-container h2.year").click(function() {
			var target = $(this).parent('.year-container').children('.items');
			jQuery(this).hasClass('close') ? Frontend.CollapsingList.Open(target) : Frontend.CollapsingList.Close(target);
			//if ($.browser.msie && $.browser.version <= 6) $('#page').css('height', 'auto').css('height', $('#page').height() + 'px');
		});
		jQuery(".year-container h2.year:first").trigger('click');
	},
	Open: function(elm) {
		elm.parent('.year-container').find('.year').addClass('open').removeClass('close');
		elm.slideDown('500');
	},
	Close: function(elm) {
		elm.parent('.year-container').find('.year').addClass('close').removeClass('open');
		elm.hide();
	}
}

// Alternate Item ==============================================
var AlternateItem = {
	Init: function() {
		jQuery(".year-container").each(function() {
			jQuery(this).find(".items .halfPod:even").addClass('clear');
		});
	}
}

// Rotating promotion images ==============================================
var RotatingImages = {
	Init: function() {
		var images = ["promo_subscribesave1.gif", "promo_guarantee2.gif", "promo_reserveseat3.gif", "promo_bookticket4.gif", "promo_getinvolve5.gif"];
		var altText = ["Subscribe and save money now", "Subscribe and guarantee yourself a year of quality theatre", "Subscribe and reserve the best seats in the house", "Subscribe and take the hassle out of booking your tickets", "Subscribe and get involved"];
		var random = Math.floor(Math.random()*images.length);
		jQuery(".rotate img").attr("src", "/Images/Promotions/" + images[random]).attr("alt", altText[random]).show();
		
	}
}

// Initialise methods onto Frontend Object ================================================================================
var Frontend = {
	CollapsingList: CollapsingList,
	AlternateItem: AlternateItem,
	RotatingImages: RotatingImages
};