$(document).ready( function($) {

  
  	$('.slideshow').each( function() {
    	var related_group = $(this).attr('rel');

    	window.setInterval("simpleSlideAction('.right-button', " + related_group + ");", 4000);
	});
		
	$('.slideshow').live('mouseover mouseout', 
		function(event) {
			if(event.type == 'mouseover'){
				$(this).children('.left-button, .right-button').stop(true, true).fadeIn();
			}
			else {
				$(this).children('.left-button, .right-button').stop(true, true).fadeOut();
			}
		}
	);
	
	$('#nav_links li').live('click', function() {
		var load_link = $(this).attr('rel');									  
	
		loadLink(load_link);
	});

	$('#content_window').load('../sections/setting-up.html', function() {
		simpleSlide({'swipe':'true'});
		
		var rel_color = $('#content_window div').attr('rel');
		navColors(rel_color);
		
	});
	
	$('.switch_button').live('click', function() {
		if($(this).hasClass('next')){
			$('#nav_links li').each( function() {
				if($(this).attr('class') != '' && $(this).attr('class') != null){
					var page_to_load = $(this).next().attr('rel');
					
					loadLink(page_to_load);
					
					return false;
					
				}
			});
		}

		if($(this).hasClass('prev')){
			$('#nav_links li').each( function() {
				if($(this).attr('class') != '' && $(this).attr('class') != null){
					var page_to_load = $(this).prev().attr('rel');
					
					loadLink(page_to_load);
					
					return false;
					
				}
			});
		}
	});

});
/*  $(function() {
    $("#revealTab").click(function() {
      $("#addresses").slideToggle('slow');
    });
  });
    $(function() {
    $("#addresses").click(function() {
      $("#addresses").slideToggle('slow');
    });
  });
*/
function navColors(color_name){	
	$('ul#nav_links li').removeAttr('class');

	$('ul#nav_links li span').each( function() {
		if( $(this).attr('class') == color_name) {
			$(this).parent().addClass(color_name);
		}
	});
}

function loadLink(load_link){
	$('#content_window').css('position','relative');							  
	$('#content_window').animate({
		'left': '20px',
		'opacity': '0'
	}, 500, "swing", function() {

		$.ajax({
			   url: '../sections/' + load_link,
			   dataType: 'html',
			   success: function(html) {
				   $('#content_window').html(html);
					simpleSlide({
						'swipe': 'true',
						'callback': function() {
							$('#content_window').animate({
								'left': '0px',
								'opacity': '1'
							}, 300, "swing", function() { 
								$('#content_window').css('position','static');
								var rel_color = $('#content_window div').attr('rel');
								navColors(rel_color);
								$('.simpleSlideStatus-window div').parent().css({
									'marginLeft': 'auto',
									'marginRight': 'auto'
								});								
							});
						}
					});
					$('.auto-slider').each( function() {							 
						var related_group = $(this).attr('rel');
						clearInterval($.autoslide);
						$.autoslide = setInterval("simpleSlideAction('.right-button', " + related_group + ");", 4000);
					});					
				}
		});
	});
}


$(document).ready(function() {
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$(".image-link").click(function() {
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
 
});

$(function() {
    $('.rollover').hover(function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    }, function() {
        var currentImg = $(this).attr('src');
        $(this).attr('src', $(this).attr('hover'));
        $(this).attr('hover', currentImg);
    });
});
