﻿var elements;
var settings;
$.fn.innerfade = function(options) {
	return this.each(function(){
		var settings = {
			speed: 'normal',
			timeout: 2000,
			type: 'sequence',
			containerheight: 'auto'
		}
		//Stop IE flicker
		if ($.browser.msie == true) {
			document.execCommand('BackgroundImageCache', false, true);
		}
		//Stop IE flicker
		if(options)
			$.extend(settings, options);
		elements = $(this).children().get();
		if (elements.length > 1) {
			$(this).parent().css('position', 'relative');
			$(this).css('height', settings.containerheight);
			for ( var i = 0; i < elements.length; i++ ) {
				$(elements[i]).css('z-index', elements.length - i).css('position', 'absolute');
				$(elements[i]).hide();
			}	
			if ( settings.type == 'sequence' ) {
			
				//$.innerfade.next(elements, settings, 1, 0);

			}
			else if ( settings.type == 'random' ) {
//				setTimeout(function(){
//					do { current = Math.floor ( Math.random ( ) * ( elements.length ) ); } while ( current == 0 )
//					$.innerfade.next(elements, settings, current, 0);
//				}, settings.timeout);
//				$(elements[0]).show();
			}
			else {
				alert('type must either be \'sequence\' or \'random\'');
			}
		}
	});
};
$.innerfade = function() {}
$.innerfade.next = function (elements, settings, current) {
    $(elements[current]).fadeOut(700);
	$(elements[current]).fadeIn(700);
	
	
	
}


//Rotate images//

function nextContent(index)
{
jQuery(document).ready(function()
    {
 		jQuery('ul#content').innerfade(
 		{
    		speed: 100, timeout: 0, type: 'sequence',containerheight: '380px'
 		});
 		/////////////////////////////Sub Menu Bar Statatements Starts//////////////////////////////////////////////////////////
 		$("ul.subnav").parent().append("<span style='position:static;'></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	    $("ul.topnav li a").mouseover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	    });
	    ///////////////////////////////////END..////////////////////////////////////////////////////////////////////////////////
 	});
$.innerfade.next(elements, settings, index);
}
