$(document).ready(function()
{
	// open links in external window	
	externalLinks();
	internalLinks();
		
	//var currentCol = getElementsByClassName("collapsable", "*", document);
	//currentCol[0].className = 'collapsable open';
	//currentCol[0].setAttribute('id', 'current');

	// jquery accordion panels HTI extension and ticketing  	
	$(".accordion h2:first");
	$(".accordion div").hide();

	$(".accordion h2").click(function(){
		$(this).next("div").slideToggle("800")
		.siblings("div:visible").slideUp("800");
		$(this).toggleClass("open");
		$(this).siblings("h2").removeClass("open");
	});
	
	// International shows - show current show's parent navigation.
	if($('#shows.int-shows').length)
	{
		$('.show-'+hatTrick.showID)
		.find('a')
		.addClass('selected')
		.end()
		.parent()
		.show()
		.parent()
		.find('a:first')
		.addClass('selected')
		.attr('id','current');
	}

	if($('input[name="action"]').attr('value') === 'login')
	{
		$('.full-episode').click(function(e)
		{
			e.preventDefault();
			$('<p class="alert">Please log-in to view full episode.</p>').insertAfter($('span.preview'));
		});
	}

});




function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}


function externalLinks() {
	if (!document.getElementsByTagName) return;  
	var anchors = document.getElementsByTagName("a");  
	for (var i=0; i<anchors.length; i++) {  var anchor = anchors[i];  
	if (anchor.getAttribute("href") &&  anchor.getAttribute("rel") == "external")  anchor.target = "_blank";  
	}
};  
		
function internalLinks() {  
	if (!document.getElementsByTagName) return;  
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {  var anchor = anchors[i];  
	if (anchor.getAttribute("href") &&  anchor.getAttribute("rel") == "internal")  anchor.target = "_self";  
	}  
};  

function selected(a){
	var currentClass = a.getAttribute('class')
	b = document.getElementById('current');
	if (b) {
		b.className = '';
		b.setAttribute('id','');
	}
	
	if (b != a) {
		a.className = currentClass + ' selected';
		a.setAttribute('id', 'current');
	}
}

function itemselected(a){
	var currentClass = a.getAttribute('class')
	bb = document.getElementById('currentsingleitem');
	if (bb) {
		bb.className = '';
		bb.setAttribute('id','');
	}
	
	if (bb != a) {
		a.className = currentClass + ' selected';
		a.setAttribute('id', 'currentsingleitem');
	}
}

function subnaveoneselected(a){
	
	var currentClass = a.getAttribute('class')
	bbb = document.getElementById('currentfirstsubnav');
	if (bbb) {
		bbb.className = '';
		bbb.setAttribute('id','');
	}
	
	if (bbb != a) {
		a.className = currentClass + ' selected';
		a.setAttribute('id', 'currentfirstsubnav');
	}
}

function subnavtwoselected(a){
	var currentClass = a.getAttribute('class')
	bbbb = document.getElementById('currentsecondsubnav');
	if (bbbb) {
		bbbb.className = '';
		bbbb.setAttribute('id','');
	}
	
	if (bbbb != a) {
		a.className = currentClass + ' selected';
		a.setAttribute('id', 'currentsecondsubnav');
	}
}

//ajax calls
function getNews(a,b){
	
	$(".newsItem").load("/news/ .newsItem",{news_id:a});
	itemselected(b);
	return false;
}

function getShow(a,b){
	
	
	$.get("/our-shows/show-detail/get-content.php",{show_id:a}, function(data){
 		conAr = data.split(",");
		$(".showItem").load("/our-shows/show-detail/ .showItem",{show_id:a},function(){
				runSwf2(conAr[0],conAr[1],conAr[2],conAr[3])
		});
		itemselected(b);
	});
	
	return false;
}

function getIntShow(a,b){
	$.get("/hattrick-international/int_shows/show-detail/get-content.php",{show_id:a}, function(data){
 		conAr = data.split(",");
		$(".showItem").load("/hattrick-international/int_shows/show-detail/ .showItem",{show_id:a},function(){
				runSwf2(conAr[0],conAr[1],conAr[2],conAr[3])
		});
		itemselected(b);
	});
	return false;
}


function getIntShowFormatOnly(a,b){
	$.get("/hattrick-international/int_shows/show-detail/get-content.php",{show_id:a}, function(data){
 		conAr = data.split(",");
		$(".showItem").load("/hattrick-international/int_shows/show-detail/index-format-only.php .showItem",{show_id:a},function(){
				runSwf2(conAr[0],conAr[1],conAr[2],conAr[3])
		});
		itemselected(b);
	});
	return false;
}

function getMember(a,b){
	$(".memberItem").load("/hattrick-international/int_shows/show-detail/ .memberItem",{mem_id:a});
	itemselected(b);
	return false;
}

function getCompanyMember(a,b){
	$(".memberItem").load("/about-us/company-members/?mem_id .memberItem",{mem_id:a});
	itemselected(b);
}

function getCompanyPlum(a){
	$(".memberItem").load("/about-us/hattrick-companies/plum.php .memberItem");
	itemselected(a);
}

function getCompanyTof(a){
	$(".memberItem").load("/about-us/hattrick-companies/tof.php .memberItem");
	itemselected(a);
}

function getCompanyInternational(a){
	$(".memberItem").load("/about-us/hattrick-companies/hatrick-international.php .memberItem");
	itemselected(a);
}

function getCompanyWritersComp(a){
	$(".memberItem").load("/about-us/hattrick-companies/the-writers-company.php .memberItem");
	itemselected(a);
}

function removeImage(a){
	a.style.backgroundImage = "none";
}



