$(document).ready(function() {

	$(window).load(function() {
		if($("body").hasClass("home")) {
			$.cookie('visited', 'true', {
				path : '/',
				secure : false
			});
		}
	});
	//generic styling //

	$("#nav li a").hover(function() {
		$(this).next().addClass('arrow-hovered');
	}, function() {
		$(this).next().removeClass('arrow-hovered');
	});

	$(".subscribe input").focusin(function() {
		if($(this).val() == 'your email address') {
			$(this).val('');
		}
	});

	$(".subscribe input").focusout(function() {
		if($(this).val() == '') {
			$(this).val('your email address');
		}
	});

	$(".sf-menu li ul").each(function() {
		$(this).find("a:last").css('border', 'none');
	});
	//init superfish //
	$('ul.sf-menu').superfish({
		autoArrows : false,
		delay : 0,
		speed : 'fast'
	});

	if(parseInt($.browser.version) == 7) {
		if($.browser.msie) {
			$(".sf-menu ul").css('overflow', 'visible');
			$(".sf-menu ul").each(function() {
				var longest = 0;
				$(this).find("li a").each(function() {
					if($(this).outerWidth() > longest) {
						longest = $(this).outerWidth();
					}
				});
				$(this).children().width(longest);
				$(this).children().children().width(longest);
			});
		}
	}

	$(".sf-menu > li").each(function() {
		$(this).find(".arrow-down").css("left", ($(this).find("a:first-child").width() / 2))
	});

	$(".video1").click(function() {
		$(".videos").html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="298" id="index" align="middle" style="left:-1px;position:relative;"><param name="movie" value="sissy/index.swf" /><param name="quality" value="medium" /><param name="bgcolor" value="#ffffff" /><param name="play" value="true" /><param name="loop" value="false" /><param name="wmode" value="transparent" /><param name="scale" value="showall" /><param name="menu" value="false" /><param name="devicefont" value="false" /><param name="salign" value="" /><param name="allowScriptAccess" value="sameDomain" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="sissy/index.swf" width="480" height="298"><param name="movie" value="sissy/index.swf" /><param name="quality" value="medium" /><param name="bgcolor" value="#ffffff" /><param name="play" value="true" /><param name="loop" value="false" /><param name="wmode" value="transparent" /><param name="scale" value="showall" /><param name="menu" value="false" /><param name="devicefont" value="false" /><param name="salign" value="" /><param name="allowScriptAccess" value="sameDomain" /><!--<![endif]--><a href="http://www.adobe.com/go/getflash"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> </a><!--[if !IE]>--></object><!--<![endif]--></object>');
	});

	$(".video2").click(function() {
		$(".videos").html('<iframe width="480" height="300" src="http://www.youtube.com/embed/7Xor25JuMWg?rel=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>');
	});

	$(".video3").click(function() {
		$(".videos").html('<iframe width="480" height="300" src="http://www.youtube.com/embed/TVaCaKx9aGs?rel=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>');
	});

	$(".video4").click(function() {
		$(".videos").html('<iframe width="480" height="300" src="http://www.youtube.com/embed/DwLprPfAm2c?rel=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>');
	});

	$(".video5").click(function() {
		$(".videos").html('<iframe width="480" height="300" src="http://www.youtube.com/embed/SAfRzrnoEqQ?rel=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>');
	});

	$(".video6").click(function() {
		$(".videos").html('<iframe width="480" height="300" src="http://www.youtube.com/embed/UjXrEmRHVfw?rel=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>');
	});

	var animating = false;


	$(".noMargin li span").click(function() {

		if (animating || $(this).hasClass('expanded')) {
			return false;
		}
		animating = true;
		
		$_ = $(this);
		$$ = $(this).next().height();

		

		if($(".expanded").length > 0) {
			$(".noMargin li span").css('background-position','0px 0px');
			$(".expanded").next().slideUp(250, function() {
				$_.css('background-position','0px 0px');
				$_.css('background-position','0px -27px');
				$(".expanded").removeClass("expanded");
				$(this).css('left', '-9999px');
				$(this).css({
					'height':'auto',
					'position':'absolute'
				});
				$_.addClass("expanded");
				$_.next().height(0).css({
				'left':'0px',
				'position':'relative'	
				}).show().animate({
					'height' : $$
				}, 250, function() {
					
					animating = false;
				});
				
			})
		} else {
			$(this).addClass("expanded");
			$_.css('background-position','0px 0px');
			$_.css('background-position','0px -27px');
			$_.next().height(0).show().css({
				'left':'0px',
				'position':'relative'	
				}).animate({
				'height' : $$
			},250, function() {
				
				animating = false;
			});
		}

	});
});

