/*
  Microzone js functions
  By Hazlitt Eastman
*/

/* functions that animate aspects of the site */

$(function() {
    $('img[image-hover]').hover(function() {
        $(this).attr('tmp', $(this).attr('src')).attr('src', $(this).attr('image-hover')).attr('image-hover', $(this).attr('tmp')).removeAttr('tmp');
    }).each(function() {
        $('<img />').attr('src', $(this).attr('image-hover'));
    });;

	$("#toggle").click(function () {
	   $('.togglelist').slideToggle();
	});
	
	$("#first_product_toggle").click(function () {
	   $('#first_product').slideToggle();
	});
	
	$("#second_product_toggle").click(function () {
	   $('#second_product').slideToggle();
	});
	
	$('p.tabletoggle').click(function() {
		$(this).siblings('ul').slideToggle("slow");
	});
	
	/*$('.product_toggles li').click(function() {
		$(this).children('ul').slideToggle("slow");
	});*/
	
	$('ul.about_us li').click(function() {
		$(this).children('ul').slideToggle("slow");
	});
	$('#s').click(function() {
		$(this).attr('value', '');
	});
	
	$('li.level_1 span').click(function() {
		var isVisible = $(this).siblings('ul').is(':visible');
		if(isVisible == true) {
			$(this).siblings('ul').slideUp("slow");
			$(this).css({color:'#ffffff'});
		} else {
			$('ul.level_2').slideUp("slow");
			$('li.level_1 span').css({color:'#ffffff'});
			$(this).css({color:'#c80011'});
			$(this).siblings('ul').delay(500).slideDown("slow");
		}
	})
	
	$('p.level_2').click(function() {
		var isVisible = $(this).siblings('div').is(':visible');
		if(isVisible == true) {
			$(this).siblings('div').slideUp("slow");
			$(this).css({color:'#ffffff'});
		} else {
			$('div.level_2').slideUp("slow");
			$('p.level_2').css({color:'#ffffff'});
			$(this).css({color:'#c80011'});
			$(this).siblings('div').delay(500).slideDown("slow");
	}
	})
	
});

/*  Functions that setup the elements of the document after it has finished downloading */

$(document).ready(function() {
	/* hide page elements */
	$('.start_closed').hide();
	$('#first_product').hide();
	$('#second_product').hide();
	$('.product_toggles li ul').hide();
	$('ul.about_us li ul').hide();
	$('ul.level_2').hide();
	$('div.level_2').hide();
		
	/* mouse over page elements */
	$('#first_product_toggle').mouseover(function() {
	    $(this).css('cursor', 'pointer');
	});
	$('#second_product_toggle').mouseover(function() {
	    $(this).css('cursor', 'pointer');
	});
	$('p.tabletoggle').mouseover(function() {
	    $(this).css('cursor', 'pointer');
	});
	$('span.white').mouseover(function() {
	    $(this).css('cursor', 'pointer');
	});
	$('p.level_2').mouseover(function() {
	    $(this).css('cursor', 'pointer');
	});
	$('h2.about_us').mouseover(function() {
	    $(this).css('cursor', 'pointer');
	});
	$('#toggle').mouseover(function() {
	    $(this).css('cursor', 'pointer');
	});
	$('#submit').mouseover(function() {
	    $(this).css('cursor', 'pointer');
	});
	$('ul.about_us li').mouseover(function() {
		$(this).children('h2').addClass('underline');
	});
	
	/* mouse out page elements */
	$('ul.about_us li').mouseout(function() {
		$(this).children('h2').removeClass('underline');
	});
	$('a.price_list').mouseover(function() {
		$(this).addClass('underline');
	});
	$('a.price_list').mouseout(function() {
		$(this).removeClass('underline');
	});
	
	/* Webkit spacing */
	if ($.browser.webkit) {
			$("p.sidebar_monster").addClass("webkit_addspace");
		}
});
