/* homepage banner slider */
$(function(){
	$('#slider2').anythingSlider({
		resizeContents      : false,
		navigationSize      : 10,
		navigationFormatter : function(index, panel){
		return ['', '', '', '', ''][index - 1];
		}
	});
	
	$("a.panel6").html("");
});

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function ddmenu_open(){
	ddmenu_canceltimer();
	ddmenu_close();
	ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function ddmenu_close(){ 
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function ddmenu_timer(){
	closetimer = window.setTimeout(ddmenu_close, timeout);
}

function ddmenu_canceltimer(){  
	if(closetimer){  
		window.clearTimeout(closetimer);
		closetimer = null;
}}

$(document).ready(function(){  
	$('#ddmenu > li').bind('mouseover', ddmenu_open)
	$('#ddmenu > li').bind('mouseout',  ddmenu_timer)
});

document.onclick = ddmenu_close;

/* toolbox slide and video slide js */
$(document).ready(function() {
	 $(".minimise").click(function(){
		$("#banner").slideToggle("slow");
		$("a.open_panel").fadeIn();
	 })
	
});

/* homepage video popup script */
$(document).ready(function() {
//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="video-close"><img src="images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=60)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});

//Close Popups and Fade Layer
$('a.video-close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.video-close').remove();  //fade them both out
    });
    return false;
});});

function goToByScroll(id){
	if($("#"+id).length > 0) {
		$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
	}
	return false;
};

function Login() {
	
if($("#username_popup").val() != "" && $("#password_popup").val()!="") {

$.ajax({
	type: 'POST',
	url: '/includes/process.php',
	async: true,
	cache: false,
	data: 'name='+ $("#username_popup").val() +'&password=' + $("#password_popup").val() + '&action=login',
	success: function(data)	{
		var str = data.split("|");
		
		if(str[0] == "ok") {
			document.location.href = str[1];	
		}
		else {
			alert("ERROR: " + str[1]);
		}
	}
});

}
};

function addToNewsletter() {

if($("#nl_email").val() != "" && $("#nl_email").val()!="email address") {

$.ajax({
	type: 'POST',
	url: '/includes/process.php',
	async: true,
	cache: false,
	data: 'email='+ $("#nl_email").val() + '&action=add_email',
	success: function(data)	{
		
		if(data == "ok") {
		alert("Thank you for your subscription.");	
		$("#nl_email").val("");
		}
		else {
		alert(data);	
		}
	}
});

}

};
