$(document).ready(onDocReady);

function onDocReady(){
	activate_drop_down();
	login_drop_down();
	activate_poll();
	$(".handler").click(doSlide);
	$(".subhandler").click(doSlide);
	$(".subgroup").children(".subcontent").hide();
    $(".edit").click(openEdit);
    $(".close").click(closeEdit);
	$("#usual2 ul").idTabs("All_Blogs");
	$("#events_subnav ul").idTabs(document.getElementById("events_default_tab").value); 
	//$("#media_player_subnav ul").idTabs(document.getElementById("media_default_tab").value); 
	$("#usual2 ul").idTabs(document.getElementById("blogs_default_tab").value); 
	$("#global_blog_subnav ul").idTabs("feeling_recently_updated");
	$("#blog_account_nav ul").idTabs("profile_blog_account_tab");
	$("#blog_post_nav ul").idTabs("add_article_tab");
	$("#event_gallery_nav ul").idTabs("event_gallery_latest_tab");

    slide_minimized();	
	
    //image swap on rollover
	$(".rollover").hover(
	 function() {
	  curr = $(this).find("img").attr("src");
	  overlen = curr.length;
	  over = curr.substr(0, overlen-4);
	  over = over+'_roll.gif';
	  $(this).find("img").attr({ src: over});
	 },
	 function() {
	  $(this).find("img").attr({ src: curr});
	 }
	)
	
	$(".rollover").find("img").each(function(i) {
	  temp = this.src;
	  prelen = temp.length;
	  pre = temp.substr(0, prelen-4);
	  pre = pre+'_roll.gif';
	  preload_image_object = new Image();
	  preload_image_object.src = pre;
	});

}

function doSlide(){
	$(this).parent(".group").children(".content").slideToggle("medium");
	$(this).parent(".subgroup").children(".subcontent").slideToggle("fast");
}

function openEdit(){
	$(this).parent(".content").children(".edit_content").show();
	$(this).parent(".content").children(".visible_content").hide();
}

function closeEdit(){
	$(this).parent(".edit_content").parent(".content").children(".visible_content").show();
	$(this).parent(".edit_content").parent(".content").children(".edit_content").hide();
}

function showsubmenu(id){
	submenu = document.getElementById('s'+id);
	for(i=1;i<=7;i++){
		if(i==id){
			submenu.style.display="block";
		} else {
			document.getElementById('s'+i).style.display="none";
		}
	}
}

function activate_drop_down(){
	$('#customise_anchor').click(show_drop_down);
	$('#drop_down_customise_close').click(hide_drop_down);
}
function show_drop_down() {
	$('#drop_down_customise').slideDown("slow");
}
function hide_drop_down() {
	$('#drop_down_customise').slideUp("slow");
}

function login_drop_down(){
	$('#login').click(show_drop_down_login);
	$('#login_close').click(hide_drop_down_login);
}
function show_drop_down_login() {
	$('#login_customise').slideDown("slow");
}
function hide_drop_down_login() {
	$('#login_customise').slideUp("slow");
}

/*---POLL---*/
function activate_poll(){
	$('.poll_anchor').toggle(show_drop_poll,hide_drop_poll);
}
function show_drop_poll() {
	$(this).children('.drop_down_poll').slideDown("slow");
}
function hide_drop_poll() {
	$('.drop_down_poll').slideUp("slow");
}
/*-------------------*/

$(document).ready(function() {
   $(".searchBox").toggleVal();
}); 

$(document).ready(function() {
   $("#footerToggle").toggleVal();
});

$(document).ready(function() {
   $("#blogToggle").toggleVal();
});

$(function() {
    $('.gallery').lightBox();
});

$(document).ready(function() {
   $("#answerToggle").toggleVal();
});

function slide_minimized()
{
    if (!document.getElementById("events_active").checked)
	    $("#events_header").click(); 
    //if (!document.getElementById("media_active").checked)
	//    $("#media_player_header").click(); 
    if (!document.getElementById("music_active").checked)
	    $("#music_header").click(); 
    if (!document.getElementById("competitions_active").checked)
	    $("#competitions_header").click(); 
    if (!document.getElementById("blogs_active").checked)
	    $("#blog_header").click(); 
}

function popup_win(url,name,w,h)
{  // no scrollbars, not resizable
    var winW = (screen.width - w) / 2;
    var winH = (screen.height - h) / 2;
    window.open(url,name,"width="+w+",height="+h+",top="+winH+",left="+winW+",toolbar=no,location=no,directories=no,menubar=no,status=no,scrollbars=no,resizable=no");
}

