﻿/* This file runs on every page, every time they are loaded. Do not remove it, it's a core file. */
/* Init - runs when document is ready. All functions which require the document to be ready should be called from here */


$(document).ready(function() {
		$(".slideshow").css("overflow", "hidden");
		
		$(".slides").cycle({
			fx: 'fade',
			pause: 1,
			prev: '.prev',
			next: '.next',	
<!--			speed:  'slow',-->
			speedIn: 'slow',  // speed of the 'in' transition 
		    speedOut: 'slow',
			timeout: 8000,
			pager:  '.thumbs', 
   			pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
            return '.thumbs li:eq(' + idx + ') a'; 
    } 
		});
		

});


$(function() {
	$("div#content").moveClass({target:"body"});
	$("div.row").columns();
	$("label.labeler").labeler();
	$(".addFirstAndLastClass").afalc({className:"addFirstAndLastClass"});
	initDatePicker();
	createTabs();
	addClassToNavigation();	
	addClassToInputElements();
	$("#twitter_feed").tweetable({username: 'LeagueACS', time: false, limit: 1});
});

function initDatePicker() {
	// Datepickers for date input fields
	$('input.date').datepicker({ dateFormat: 'dd/mm/yy' });
}

// Open an AJAX dialog
function openDialog(url,title,width,height) {
	// Width and height
	var w = 500;
	var h= 300;
	if(width) {
		w = width;	 
	}
	if(height) {
		h = height;	 
	}
	 // Reset the dialog
    $("#dialog").html('').dialog('destroy'); 
    // Set up dialog
    $("#dialog").dialog({
		width: w,
		height: h,
		modal: true,
		title: title,
		cache: false
    }); 
    // Fetch content
    $.ajax({
		type: "GET",
		url: url,
		data: "ajax=1",
		success: function(data){
			$("#dialog").html(data);
		}
    });
}

// Replace alrt boxes with a much nicer alternative
function ajaxAlert(msg) {
	if($('#alert').length == 0) {
		$("body").append('<div id="alert"></div>');	
	}
    $('#alert').dialog('destroy').html(msg).dialog({
		dialogClass: 'alert',
		width: 200,
		minHeight: 80,
		modal: true,
		cache: false,
		buttons: { "Ok": function() { $(this).dialog("close"); } }
    }); 
}

/* create tabs function - to allow for tabs to be called by other means */
function createTabs(){
	$(".tabs").tabs();
	$("#tabs").tabs();
	$("#scrolling_tabs").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);  
    $("#scrolling_tabs").hover(  
        function() {  
            $("#scrolling_tabs").tabs("rotate",0,true);  
        },  
        function() {  
            $("#scrolling_tabs").tabs("rotate",5000,true);  
        }  
    );
}

// add classes to navigation to display popup
function addClassToNavigation() {	
	$(".topnav ul li:not(div.nav_popup ul li)").hoverIntent(function() {														
		$(".topnav ul li:not(this)").removeClass("showPopup");
		$(this).addClass("showPopup");
		$(this).find("div.nav_popup").addClass("displayPopup");
	},function(){});
	
	$(".topnav ul li div.nav_popup").mouseleave(function() {
		if($(".topnav ul li div.nav_popup").hasClass("displayPopup")) {
			$(this).removeClass("displayPopup");
			$(".topnav ul li").removeClass("showPopup");
		}
		else {
			
		}
	});
	
	$("#header .inner").mouseenter(function() {
		$(this).addClass("hover");
	});
	
	$("#header .inner").mouseleave(function() {
		$(this).removeClass("hover");
	});
};

// add classes to input elements
function addClassToInputElements() {
	$("input[type=text]").addClass("input_type_text");
	$("input[type=password]").addClass("input_type_password");
	$("input[type=radio]").addClass("input_type_radio");
	$("input[type=checkbox]").addClass("input_type_checkbox");
	$("input[type=submit]").addClass("input_type_submit");
	$("input[type=image]").addClass("input_type_image");
	$("input[type=button]").addClass("input_type_button");
	$("input[type=file]").addClass("input_type_file")
};