﻿var activepic;
var activetext;
$(document).ready(function() {

    //## Function to handle colour alteration animations
    $("nav a").hover(function() {

        $(this)
            .stop()
            .animate({
                backgroundColor: "#FFFFFF"
            }, 600);
    }, function() {

        $(this)
            .stop()
            .animate({
                backgroundColor: "#EEEEEE"
                //opacity: 0.50
            }, 400)
    });

    //## Function to slide up text overlay layers on homepage
    jQuery.fn.jslider = function() {
        this.animate({
            top: '170px'
        },
    'slow');
    }

    //## Select the first homepage image to display
    activepic = jQuery('#homepageimgs div.homepageimgitem:first'); //## Activate the first pic
    activepic.siblings('div').hide(); //## Hide all other pics

    activetext = activepic.children(2); //## Activate the first lot of text
    
    //## Call a function at a specififed interval to rotate through the homepage images
    setInterval("show_next_pic(activepic, activetext)", 10000); // Set the rotate time to 6 seconds

    jQuery('#homepageimgs').show();
    
    //## Slide the text in over the image
    $(activetext).jslider();

    //## Function to slide up text overlay layers on homepage
    jQuery.fn.medjslider = function() {
        this.animate({
            top: '286px'
        },
    'slow');
    }

    //## Select the first homepage image to display
    medactivepic = jQuery('#mediaimgs div.mediaimgitem:first'); //## Activate the first pic
    medactivepic.siblings('div').hide(); //## Hide all other pics

    medactivetext = medactivepic.children(2); //## Activate the first lot of text

    //## Call a function at a specififed interval to rotate through the homepage images
    setInterval("med_show_next_pic(medactivepic, medactivetext)", 15000); // Set the rotate time to 6 seconds

    jQuery('#mediaimgs').show();

    //## Slide the text in over the image
    $(medactivetext).medjslider();

    $("#slider").easySlider({
        auto: true,
        continuous: true,
        nextText: '',
        prevText: '',
        pause: 10000,
        speed: 1000
    });


    //## CMS CONTROLS
    
    //## Function to slide the cms div up from the bottom of the screen
    jQuery.fn.cmsTxtToggle = function() {
        this.animate({
            opacity: 0.95,
            height: 'toggle'
        },
            'slow', 'easeOutSine');
    }

    //## Assign the above function to the click action of the class of buttons named 'editBtn'
    //## and to perform other relevant actions
    $('.editBtn').click(function(e) {
        $('.cmsTextContainer').css({ 'backgroundColor': '' });
        $('.cms_textpanel').hide();
        var cmstxtObj = $('#cms_' + this.id);
        $(cmstxtObj).cmsTxtToggle();

        var txttoeditobj = $('#cms_txt_container_' + this.id);
        $(txttoeditobj).css({ 'backgroundColor': '#FFCC00' })
    });

    //## defaults
    jQuery.easing.def = 'easeOutQuad';

    //## functions
    jQuery.fn.jsliderx = function() {
        this.animate({
            height: 'toggle'
        },
            'slow', 'easeOutSine');
    }

    //##  event assignments
    $('#imagetab').click(function() {
        $('#adminMenu').jsliderx();
    });

    $("a.actLink").fancybox({
        'hideOnContentClick': true,
        'easingIn'      :   'easeOutBack',
        'easingOut'     :   'easeInBack',
   		'transitionIn'	:	'elastic',
   		'transitionOut':    'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200
    });

    $("a.venuelink").fancybox({
        'hideOnContentClick': true,
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'speedIn': 400,
        'speedOut': 200
    });

    //## PAST SHOWS
    var configYear = {
        over: yearOut, // function = onMouseOver callback (REQUIRED)    
        timeout: 500, // number = milliseconds delay before onMouseOut    
        out: yearIn // function = onMouseOut callback (REQUIRED)    
    };

    function yearOut() {
        $(this).css({ 'background-color': '#FFFFFF' });
        $(this).find('.showMonth').css({ 'visibility': 'visible' });
        $(this).find('.showMonth')
						.animate({
						    width: '552px'
						}, 600);
    }

    function yearIn() {
        $(this).find('.showMonth')
						.animate({
						    width: '0px'
						}, 600);
		$(this).css({ 'background-color': '#FFFFFF' });
    }

    $(".showYear li").hoverIntent(configYear);

    var configMonth = {
        over: monthOut, // function = onMouseOver callback (REQUIRED)    
        timeout: 500, // number = milliseconds delay before onMouseOut    
        out: monthIn // function = onMouseOut callback (REQUIRED)    
    };

    function monthOut() {
        $(".showDay").hide();
        $("#" + this.id + "Days").css({ 'visibility': 'visible' });
        $("#" + this.id + "Days").css({ 'display': 'inline' });
    }

    function monthIn() {

    }

    $(".showMonth li").hoverIntent(configMonth);

    $('.showDay').mouseleave(function() {
        $(this).css({ 'display': 'none' });
        $(this).css({ 'visibility': 'hidden' });
    });

});

//## The below function repeatedly gets called, to do the rotating of the homepage images
function show_next_pic(p, t) {

    $('.imgtextoverlay').css({ 'top': '250px' });

    jQuery(p).fadeOut('slow');

    var next_pic = jQuery(p).next();
    var next_text;
    if (!next_pic.attr('class')) {
        next_pic = jQuery('#homepageimgs div.homepageimgitem:first');
    }
    next_pic.fadeIn('slow');

    activepic = next_pic;

    activetext = activepic.children(2); 

    $(activetext).jslider();
    
}

//## The below function repeatedly gets called, to do the rotating of the media images
function med_show_next_pic(p, t) {

    $('.mediaimgtextoverlay').css({ 'top': '324px' });

    jQuery(p).fadeOut('slow');

    var next_pic = jQuery(p).next();
    var next_text;
    if (!next_pic.attr('class')) {
        next_pic = jQuery('#mediaimgs div.mediaimgitem:first');
    }
    next_pic.fadeIn('slow');

    medactivepic = next_pic;

    medactivetext = medactivepic.children(2);

    $(medactivetext).medjslider();

}


