$(function() {
	// Let the page know that a javascript enabled broswer is being used
	$('html').addClass('js');

	// Calculate total width of list items
	arrangeMenu();

	// Get the slideshow type by checking the id
	var slidetype = $('.items-big').attr('id');
	
	
	/*
	* set all features to the same height
	*/
	
	fixHeight();
	
	backgroundHeigth();
	
	
	// XHTML Strict new windows
    // NOTE: For windows to open in new tab/window add rel="external" to the link
    if(externalLinksInNewWindow) {
        externalLinks();
    }
	
	
	if ($('.item-slideshow').length > 1) {
		$(".scrollable-big").scrollable({circular: true}).navigator(".slideshow-tabs").autoscroll(10000);
		var api = $(".scrollable-big").data("scrollable");
	}
	var timeoutID;

	if (api) {

		api.onBeforeSeek(function() { // called before scroll
		
			clear_time_out(timeoutID);
			$('.slideshow-text').each(function(){
				$(this).stop();
				$(this).css({display:'none'});
			});
	
		});
		
	
		api.onSeek(function() { // called after scroll
		
			// When the slide scrolls off you need to get eh following text to come on so:
			var currentIndex;
			var intLength = $('.item-slideshow').length;
			
			//alert(this.getIndex());
			
			currentIndex = this.getIndex()+1;

			
			//$('.item-slideshow').eq(currentIndex).css({'opacity':0.5});
			thisslide = $('.item-slideshow').eq(currentIndex);
			
			if ($(thisslide).has('div.slideshow-text').length) {

						var divText = $(thisslide).children('div.slideshow-text');
						
						
						if (slidetype == 'homeslideshow') {
							clear_time_out(timeoutID);
							timeoutID = window.setTimeout( function(){
								divText.css({ left: '960px', display: 'block' });
								divText.animate({
								    left: '630px',
								    height: '325px'
								  }, 500, function() {
								    clear_time_out(timeoutID);
								});
							}, 2000);
			
						} else {
							clear_time_out(timeoutID);
							timeoutID = window.setTimeout( function(){
								divText.css({ 'left': '-315px', 'display': 'block', 'height': '325px'});
								divText.animate({
								    left: '0px',
									height: '325px'
								  }, 500, function() {
								    clear_time_out(timeoutID);
								});
							}, 2000);
						
						}
				

				
			}

	
	
		});
		
		// Set up first
		
	
		thisslide = $('.item-slideshow').eq(1);
		if ($(thisslide).has('div.slideshow-text').length) {
		
			var divText = $(thisslide).children('div.slideshow-text');
		
			if (slidetype == 'homeslideshow') {
			
				divText.css({ left: '960px' });
				clear_time_out(timeoutID);
				timeoutID = window.setTimeout( function(){
					divText.animate({
					    left: '630px',
					    height: '325px'
					  }, 500, function() {
					    clear_time_out(timeoutID);
					});
				}, 2000);
				
			} else {
			
				divText.css({ left: '-315px' })
				clear_time_out(timeoutID);
				timeoutID = window.setTimeout( function(){
					divText.animate({
					    left: '0px',
						height: '325px'
					  }, 500, function() {
					    clear_time_out(timeoutID);
					});
				}, 2000);
			
			}
		}



	}	
	

	

});
