// When the document loads do everything inside here ...

$(document).ready(
	function(){
		$('.testme').load('../php/bsrlmain.php');	//by default initally load text from bsrlmain.php

   	$("#commentForm").validate();

		$('#nav a').click(
			function(){ //start function when any link is clicked
				var inner_content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file
				sendValue($(this).attr("title"));
		}); //close click
		 
		$('#menu_body a').click(
			function() { //start function when any link is clicked
				var inner_content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file
				sendValue($(this).attr("title"));
		}); //close click

		$("#firstpane p.menu_head").click(
			function(){ //slides the element with class "menu_body" when paragraph with class "menu_head" is clicked
				$(this).css({backgroundImage:"url(../srl/images/down.png)"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
       	$(this).siblings().css({backgroundImage:"url(../srl/images/left.png)"});
		});
	
		// Launch MODAL BOX if the Login Link is clicked
		$("#login_link").click(
			function(){
//$.modal("<div><h1>SimpleModal</h1></div>");
//				alert("Made it!");
				$('#login_form').modal();
		});

// Start of Submit Validation -->

	//if submit button is clicked
	$('#submit').click(function () {		
	//alert("Submitted!!");	
		//Get the data from all the fields
		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var website = $('input[name=website]');
		var comment = $('textarea[name=comment]');

		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		if (name.val()=='') {
			name.addClass('hightlight');
			return false;
		} else name.removeClass('hightlight');
		
		if (email.val()=='') {
			email.addClass('hightlight');
			return false;
		} else email.removeClass('hightlight');
		
		if (comment.val()=='') {
			comment.addClass('hightlight');
			return false;
		} else comment.removeClass('hightlight');
		
		//organize the data properly
		var data = 'submit=SubmitMe' + '&name=' + name.val() + '&email=' + email.val() + '&website=' + website.val() + '&comment=' + encodeURIComponent(comment.val());
		
		//disabled all the text fields
		$('.text').attr('disabled','true');
		
		//show the loading sign
		$('.loading').show();
		
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "../php/bsrlmain.php",
			
			//POST method is used
			type: "POST",

			//pass the data			
			data: data,		
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {				
				//if process.php returned 1/true (send mail success)
				if (html!=1) {					
					//hide the form
					$('.form').fadeOut('slow');					
					
					//show the success message
					$('.done').fadeIn('slow');
					
				//if process.php returned 0/false (send mail failed)
				} else alert('Sorry, unexpected error. Please try again later.');				
			}		
		});
		
		//cancel the submit button default behaviours
		return false;
	});	
// End of Submit Validation -->








		$("h3").click(function(){
			var inner_content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file
			//alert(inner_content_show);

			if(inner_content_show =="Register"){
				//Do Nothing
				window.open("srl/text/signup.html");
			//alert("<h3> - "+inner_content_show);
			}
			else if(inner_content_show =="GameResults"){
				//Do Nothing
				window.open("srl/text/results.html");
			}
			else if(inner_content_show =="Cup"){
				sendValue(inner_content_show);
			}
			else if(inner_content_show =="ALogin"){
				//Do Nothing
			}
			else if(inner_content_show =="Contact Us"){
				//Do Nothing
			}
			else if(inner_content_show =="Reg"){
				sendValue(inner_content_show);
			}
			else if(inner_content_show =="Pla"){
				sendValue(inner_content_show);
			}
			else if(inner_content_show =="Home"){
				parentAccordion2.pr(-1);
				sendValue(inner_content_show);
			}
			else if(inner_content_show =="Login"){
				parentAccordion2.pr(-1);
				sendValue(inner_content_show);
			}
			else if(inner_content_show =="xRegister"){
				parentAccordion2.pr(-1);
				sendValue(inner_content_show);
			}
			else if(inner_content_show =="T1S"){
				sendValue(inner_content_show);
			}
			else if(inner_content_show =="Top Scorers Cup"){
				sendValue("TopSC");
			}
			else if(inner_content_show =="Top Scorers Regular Season"){
				sendValue("TopSR");
			}
			else if(inner_content_show =="Top Scorers Playoffs"){
				sendValue("TopSP");
			}
			else if(inner_content_show =="Playoff Standings"){
				sendValue("PlyST");
			}
			else {
				sendValue(inner_content_show);
				//alert(inner_content_show);
			}
		});
}); //close


function sendValue(str){
	//alert(str);
	
	if(str == 'Home'){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		$(".junk").html(return_value);
		$(".testme").hide();
	}
	else if(str == 'News'){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		$(".junk").html(return_value);
		$(".testme").hide();
	}
	else if(str == 'BSRL Details'){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		$(".junk").html(return_value);
		$(".testme").hide();
	}
	else if(str == 'Latest Results'){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		$(".junk").html(return_value);
		$(".testme").hide();
	}
	else if(str == 'Regular Season Standings'){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=regstandingsheader", async: false }).responseText;
		$(".junk").html(return_value);
		
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
	else if(str == 'Cup Standings'){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=cupstandingsheader", async: false }).responseText;
		$(".junk").html(return_value);
		
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
	else if(str.match("TR")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=rosterheader", async: false }).responseText;
		//alert(return_value);
		$(".junk").html(return_value);
		
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
	else if(str.match("xRegister")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".junk").html(return_value);
		$(".testme").hide();
	}
	else if(str.match("Login")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".junk").html(return_value);
		$(".testme").hide();
	}
	else if(str.match("isLoggedIn")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		return(return_value);
	}
	else if(str.match("LoginFailure")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		return(return_value);
	}
	else if(str.match("Cup")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=cupheader", async: false }).responseText;
		//alert(return_value);
		$(".junk").html(return_value);
		
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
	else if(str.match("Reg")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=regheader", async: false }).responseText;
		//alert(return_value);
		$(".junk").html(return_value);
		
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
	else if(str.match("Pla")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=plaheader", async: false }).responseText;
		//alert(return_value);
		$(".junk").html(return_value);
		
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
	else if(str.match("TopSC")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=tscheader", async: false }).responseText;
		//alert(return_value);
		$(".junk").html(return_value);

		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
	else if(str.match("TopSR")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=tssheader", async: false }).responseText;
		//alert(return_value);
		$(".junk").html(return_value);

		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
	else if(str.match("TopSP")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=tspheader", async: false }).responseText;
		//alert(return_value);
		$(".junk").html(return_value);

		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
	else if(str.match("PlyST")){
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=plystandingsheader", async: false }).responseText;
		$(".junk").html(return_value);
		
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
	else if(str == 'Goal Diggers' || str == 'Rams' || str == 'Gunners' || 
					str == 'Hammers' || str == 'Hawks' || str == 'Panthers' ||
					str == 'Seagulls' || str == 'Wanderers' || str == 'Schedule' || str == 'Standings' || str == 'Top Scorers'){
		//var return_value= $.ajax({ type: "GET", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//$(".junk").html(return_value);
		//$(".testme").hide();
	}
	else {
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page=TeamScheduleHeader", async: false }).responseText;
		//alert(return_value);
		$(".junk").html(return_value);
		
		var return_value= $.ajax({ type: "POST", url: "../php/bsrlmain.php", data: "page="+str, async: false }).responseText;
		//alert(return_value);
		$(".testme").html(return_value);
		$(".testme").show();
	}
}

// Instance #1 of TINY
var TINY={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

TINY.accordion=function(){
	function slider(n){this.n=n; this.a=[]}
	slider.prototype.init=function(t,e,m,o,k){
		var a=T$(t), i=s=0, n=a.childNodes, l=n.length; this.s=k||0; this.m=m||0;
		for(i;i<l;i++){
			var v=n[i];
			if(v.nodeType!=3){
				this.a[s]={}; this.a[s].h=h=T$$(e,v)[0]; this.a[s].c=c=T$$('div',v)[0]; h.onclick=new Function(this.n+'.pr(0,'+s+')');
				if(o==s){h.className=this.s; c.style.height='auto'; c.d=1}else{c.style.height=0; c.d=-1} s++
			}
		}
		this.l=s
	};
	slider.prototype.pr=function(f,d){
		for(var i=0;i<this.l;i++){
			var h=this.a[i].h, c=this.a[i].c, k=c.style.height; k=k=='auto'?1:parseInt(k); clearInterval(c.t);

//alert("h= "+h.id+" c= "+c.id+" k= "+k.id);
if(h.id != "wow"){

			if((k!=1&&c.d==-1)&&(f==1||i==d)){
				c.style.height=''; c.m=c.offsetHeight; c.style.height=k+'px'; c.d=1; h.className=this.s; su(c,1)
			}else if(k>0&&(f==-1||this.m||i==d)){
				c.d=-1; h.className=''; su(c,-1)
			}
		}
	}
	};
	
	function su(c){c.t=setInterval(function(){sl(c)},20)};

	function sl(c){
		var h=c.offsetHeight, d=c.d==1?c.m-h:h; c.style.height=h+(Math.ceil(d/5)*c.d)+'px';
		c.style.opacity=h/c.m; c.style.filter='alpha(opacity='+h*100/c.m+')';
		if((c.d==1&&h>=c.m)||(c.d!=1&&h==1)){if(c.d==1){c.style.height='auto'} clearInterval(c.t)}
	};
	return{slider:slider}
}();

// Instance #2 of TINY
var TINY2={};

function T2$(i){return document.getElementById(i)}
function T2$$(e,p){return p.getElementsByTagName(e)}

TINY2.accordion=function(){
	function slider(n){this.n=n; this.a=[]}
	slider.prototype.init=function(t,e,m,o,k){
		var a=T2$(t), i=s=0, n=a.childNodes, l=n.length; this.s=k||0; this.m=m||0;
		for(i;i<l;i++){
			var v=n[i];
			if(v.nodeType!=3){
				this.a[s]={}; this.a[s].h=h=T2$$(e,v)[0]; this.a[s].c=c=T2$$('div',v)[0]; h.onclick=new Function(this.n+'.pr(0,'+s+')');
				if(o==s){h.className=this.s; c.style.height='auto'; c.d=1}else{c.style.height=0; c.d=-1} s++
			}
		}
		this.l=s
	};
	slider.prototype.pr=function(f,d){
		for(var i=0;i<this.l;i++){
			var h=this.a[i].h, c=this.a[i].c, k=c.style.height; k=k=='auto'?1:parseInt(k); clearInterval(c.t);

//alert("h= "+h.id+" c= "+c.id+" k= "+k.id);
if(h.id != "wow"){

			if((k!=1&&c.d==-1)&&(f==1||i==d)){
				c.style.height=''; c.m=c.offsetHeight; c.style.height=k+'px'; c.d=1; h.className=this.s; su(c,1)
			}else if(k>0&&(f==-1||this.m||i==d)){
				c.d=-1; h.className=''; su(c,-1)
			}
		}
	}
	};
	
	function su(c){c.t=setInterval(function(){sl(c)},20)};

	function sl(c){
		var h=c.offsetHeight, d=c.d==1?c.m-h:h; c.style.height=h+(Math.ceil(d/5)*c.d)+'px';
		c.style.opacity=h/c.m; c.style.filter='alpha(opacity='+h*100/c.m+')';
		if((c.d==1&&h>=c.m)||(c.d!=1&&h==1)){if(c.d==1){c.style.height='auto'} clearInterval(c.t)}
	};
	return{slider:slider}
}();

