﻿$(document).ready(
		function() {
		    $('#MainHero').innerfade({
		        speed: 2000,
		        timeout: 4000,
		        type: 'sequence',
		        containerheight: '345px'
		    });

		    //$('#HomeSiteRotational1').innerfade({
		    //    speed: 2000,
		    //    timeout: 4000,
		    //    type: 'sequence',
		    //    containerheight: '126px'
		    //});

		    //$('#HomeSiteRotational2').innerfade({
		    //    speed: 2000,
		    //    timeout: 4000,
		    //    type: 'sequence',
		    //    containerheight: '126px'
		    //});

		    //$('#HomeSiteRotational3').innerfade({
		    //    speed: 2000,
		    //    timeout: 4000,
		    //    type: 'sequence',
		    //    containerheight: '126px'
		    //});

		    //$('#HomeSiteRotational4').innerfade({
		    //    speed: 2000,
		    //    timeout: 4000,
		    //    type: 'sequence',
		    //    containerheight: '126px'
		    //});

		    $('.rollover').mouseover(function(evt) {
		    //To do, make a bit more glamarous rather than treversing up parents
		        var rel = $(evt.target).attr('rel');
		        var currimg = $(evt.target).parent().parent().parent().parent().find('.imageSection img:visible');
		        var img = $(evt.target).parent().parent().parent().parent().find('.imageSection img[rel="' + rel + '"]');
		        if (img.length > 0) {
		            currimg.hide();
		            img.show();
		        };
		    });

		    $(".homeLpOpener").click(function(evt) {
		        //First grab the div to be animated
		        var myDiv = $(evt.target).parent().parent().find('.homeLpBlurb');

		        if ($(evt.target).attr('class').indexOf('Opener') > 0) {
		            //Lets Open the div		            
		            myDiv.animate({ height: 280 }, 500, attachClass($(evt.target), 'lpCloser', 'lpOpener'));
		        }
		        else {
		            //Lets Close the div
		            myDiv.animate({ height: 92 }, 500, attachClass($(evt.target), 'lpCloser', 'lpOpener'));
		        }

		        return false;
		    });

		    $("#mainBlurbOpener").click(function(evt) {
		        if ($(evt.target).attr('class').indexOf('Opener') > 0) {
		            //Lets Open the div
		            $('#blurbInner').animate({ height: 300 }, 500, attachClass($(evt.target), 'blurbCloser', 'blurbOpener'));
		        }
		        else {
		            //Lets Close the div
		            $('#blurbInner').animate({ height: 165 }, 500, attachClass($(evt.target), 'blurbCloser', 'blurbOpener'));
		        }

		        return false;
		    });

		    //Adjust the height of the landing page grey panel background to look nice
		    var height = $('#homeRight').height() - 271;
		    //Only adjust height of LP panel if it is visible (i.e has a height value)
		    if ($('#homeLandingPages').val() != null) {
		        if (height > $('#homeLandingPages').height()) {
		            $('#homeLandingPages').css('height', height);
		        }
		    }

            

		}
	);

		function attachClass(myDiv,closerClassName, openerClassName) {
		    //Toggles the classes on the divs to open n shut
		    //Grab the bottom bar class name before removing it
		    var className = myDiv.attr('class');
		    myDiv.removeClass(className);
		    
		    //Are we orange or blue
		    if (className.indexOf('Orange') > 0) {
		        //Orange it is!!, now toggle the open n shut class		        
		        if (className.indexOf('Opener') > 0) {
		            myDiv.addClass(closerClassName + 'Orange');
		        }
		        else {
		            myDiv.addClass(openerClassName + 'Orange');
		        }
		    }
		    else if (className.indexOf('Blue') > 0) {
		        //Blue it is !!
		        if (className.indexOf('Opener') > 0) {
		            myDiv.addClass(closerClassName + 'Blue');
		        }
		        else {
		            myDiv.addClass(openerClassName + 'Blue');
		        }
		    }
		}

		
