window.site_url = 'http://www.sleepyboy.com/';
$(document).ready(function() {
	slideTimeout = setTimeout("change_slide()", 6000);
	window.doneslide = true;
	$(".slideshow-content").hide();
	$("#slide1").show();
	$("#slideshow-item1").css({
		"border"		: "1px solid #fff",
		"margin-left"	: "7px",
		"margin-top"	: "6px",
		"margin-bottom"	: "-1px"
	});
	
	$('#login-box input[type="text"],#login-box input[type="password"]')
	.focus(function() {
		if (this.value == this.defaultValue) {
			this.value = '';
		}
	})
	
	.blur(function() { 
		if ($.trim(this.value) == '') {
			this.value = this.defaultValue;
		}
	});
	var new_input = $("<input>");
	new_input.attr("type", "text").addClass("login-text").css("margin-top", "10px").val('Password').attr('id', 'login-pass-box');
	var pass_input = $("<input>");
	pass_input.attr("type", "password").addClass("login-text").css("margin-top", "10px").val('').attr('id', 'login-pass-box').attr('name', 'pass');
	
	new_input.focus(function() {
		new_input.replaceWith(pass_input);
		pass_input.focus();
	});
	
	$('#login-pass-box').replaceWith(new_input);
	
	$('dd a.slide').click(function () {
		// Check if the clicked submenu is visible, if so, hide it
		if ($(this).next().next().is(":visible")) {
			// Animate the slideup of the submenu
			$(this).next().next().slideUp(200, function() {
				// Change the arrow image
				$(this).prev().attr("src", window.site_url+"new_site/img/open_region.png");
				// Change the css of the link so it looks like a normal button
				$(this).prev().prev().css({
					'background-image'		: "url('"+window.site_url+"new_site/img/menu_seperator.png')",
					'background-repeat'		: 'no-repeat',
					'background-position'	: 'bottom',
					'color'					: '#fff'
				});
				// Change the css of the list item
				$(this).parent("dd").css({
					'background-image'		: "url('"+window.site_url+"new_site/img/menu_button_bg.png')",
					'background-repeat'		: "repeat-y",
					'background-color'		: "transparent"
				});
					$('a:first', $(this).parent()).css({'background-color': 'transparent'});
			});
		}
		else {
			if ($('dd ul:visible').length) {
			
				// Animate the slideup of the submenu
				$('dd ul:visible').slideUp(200, function() {
				
					// Change the arrow image
					$(this).prev().attr("src", window.site_url+"new_site/img/open_region.png");
					// Change the css of the link so it looks like a normal button
					$(this).prev().prev().css({
						'background-image'		: "url('"+window.site_url+"new_site/img/menu_seperator.png')",
						'background-repeat'		: 'no-repeat',
						'background-position'	: 'bottom',
						'color'					: '#fff'
					});
					// Change the css of the list item
					$(this).parent("dd").css({
						'background-image'		: "url('"+window.site_url+"new_site/img/menu_button_bg.png')",
						'background-repeat'		: "repeat-y",
						'background-color'		: "transparent"
					});
					$('a:first', $(this).parent()).css({'background-color': 'transparent'});
					
				});
									
			}

			// Change the arrow image
			$(this).next().attr("src", window.site_url+"new_site/img/close_region.png");
			// Animate the slidedown of the 
			$(this).next().next().slideDown(500);
			// Change the css of the link so it looks like its in the list
			$(this).css({
				'background-image'		: "none",
				'color'					: '#000',
				'background-color'		: "#ff9900"
			});
			// Change the css of the list item so it will look like the list
			$(this).parent("dd").css({
				'background-image'		: "none",
				'background-color'		: '#ffcc00'
			});
		}
		
		return false;
	});
});

function show_slide(id) {
	// Cancel the current timeout for slide change
	window.clearTimeout(slideTimeout);
	
	// If the clicked id isnt the current page and the slide is done sliding, change slide
	if (!$("#slide"+id).is(":visible") && window.doneslide == true) {
		// Set as false when the slideshow is about to change page
		window.doneslide = false;
		
		// Get the id of the current slide page
		current_id = $(".slideshow-content:visible").attr("id").replace("slide", "");
		
		// Change the border of the link
		$("#slideshow-item"+id).css({
			"border"		: "1px solid #fff",
			"margin-left"	: "7px",
			"margin-top"	: "6px",
			"margin-bottom"	: "-1px"
		});
		$("#slideshow-item"+current_id).css({
			"border"		: "0",
			"margin-left"	: "8px",
			"margin-top"	: "7px",
			"margin-bottom"	: "0"
		});
		
		// If the browser is iexplorer, dont use fade effect.
		if ($.browser.msie) {
			$("#slide"+current_id).hide();
			$("#slide"+id).show();
			
			// Set as true when its done sliding
			window.doneslide = true;
		}
		else {
			$("#slide"+current_id).fadeOut('slow');
			$("#slide"+id).fadeIn('slow', function () {
				// Set as true when its done sliding
				window.doneslide = true;
			});
		}
	}
	slideTimeout = setTimeout("change_slide()", 10000);
}

function change_slide() {
	if (window.doneslide == true) {
		// Set as false when the slideshow is about to change page
		window.doneslide = false;
		
		// Get the id of the current slide page
		current_id = $(".slideshow-content:visible").attr("id").replace("slide", "");
		
		// If it isnt the last page, show the next page
		if (current_id != 6) {
			// Get the id of the next slide page
			next_id = $(".slideshow-content:visible").next().attr("id").replace("slide", "");
			
			// Change the border of the link
			$("#slideshow-item"+next_id).css({
				"border"		: "1px solid #fff",
				"margin-left"	: "7px",
				"margin-top"	: "6px",
				"margin-bottom"	: "-1px"
			});
			$("#slideshow-item"+current_id).css({
				"border"		: "0",
				"margin-left"	: "8px",
				"margin-top"	: "7px",
				"margin-bottom"	: "0"
			});
			
			// If the browser is iexplorer, dont use fade effect.
			if ($.browser.msie) {
				$("#slide"+next_id).show();
				$("#slide"+current_id).hide();
				
				// Set as true when its done sliding
				window.doneslide = true;
				
				// Start the timeout again
				slideTimeout = setTimeout("change_slide()", 6000);
			}
			// If its another browser than iexplorer, change slide with fade effect.
			else {
				$("#slide"+current_id).fadeOut('slow');
				$("#slide"+next_id).fadeIn('slow', function () {
					// Set as true when its done sliding
					window.doneslide = true;
					
					// Start the timeout again
					slideTimeout = setTimeout("change_slide()", 6000);
				});
				
			}
		}
		else {
			// Change the border of the link
			$("#slideshow-item1").css({
				"border"		: "1px solid #fff",
				"margin-left"	: "7px",
				"margin-top"	: "6px",
				"margin-bottom"	: "-1px"
			});
			$("#slideshow-item6").css({
				"border"		: "0",
				"margin-left"	: "8px",
				"margin-top"	: "7px",
				"margin-bottom"	: "0"
			});
		
			// If the browser is iexplorer, dont use fade effect.
			if ($.browser.msie) {
				$("#slide1").show();
				$("#slide6").hide();
				
				// Set as true when its done sliding
				window.doneslide = true;
				
				// Start the timeout again
				slideTimeout = setTimeout("change_slide()", 6000);
			}
			// If its another browser than iexplorer, change slide with fade effect.
			else {
				$("#slide6").fadeOut('slow');
				$("#slide1").fadeIn('slow', function () {
					// Set as true when its done sliding
					window.doneslide = true;
					
					// Start the timeout again
					slideTimeout = setTimeout("change_slide()", 6000);
				});
				
			}
		}
	}
}

