/**
 * script.js
 *
 * 1Serpent
 * Design, Development and Managed Hosting
 * http://1serpent.com/
 *
 * Adds some magic to our pretty stuff.
 */

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

	// Hide noscript
	$('#noscript').hide();

	// Drop-down menu navigation fix
	$("ul.menu > li").hover(function() {
		$(this).addClass("sp_hover");
	}, function() {
		$(this).removeClass("sp_hover");
	});

	// Philosophy
	function goToByScroll(id){
		$('html,body').animate({scrollTop: $(id).offset().top - 30},'slow');
	}
	
	$('#sp_philosophy').hide();
	$('.philosophylink a').toggle(function() {
		$('#sp_philosophy').slideDown();
		// goToByScroll('#sp_philosophy');
		return false;
	}, function() {
		$('#sp_philosophy').slideUp();
		return false;
	});

	// Fading niceness
	// jQuery("ul#sp_boxes").hide();
	// jQuery("ul#sp_boxes").fadeIn(6000);

	// Display img alt tags
	jQuery("#sp_boxes img").hover(
	function() {
		jQuery("#sp_boxes_alt").html(jQuery(this).attr("alt"));
	},
	function() {
		jQuery("#sp_boxes_alt").html("");
	});

	// Popups
	jQuery('a.sp_popup[href^=#]').click(function() {
		var popID = jQuery(this).attr('rel');
		var popURL = jQuery(this).attr('href');

		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1];

		jQuery('#' + popID).fadeIn(90).css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="sp_close">Close</a>');

		var popMargTop = (jQuery('#' + popID).height() + 80) / 2;
		var popMargLeft = (jQuery('#' + popID).width() + 80) / 2;

		jQuery('#' + popID).css({
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});

		jQuery('body').append('<div id="sp_fade"></div>');
		jQuery('#sp_fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();

		return false;
	});

	jQuery('a.sp_close, #sp_fade').live('click', function() {
		jQuery('#sp_fade , .sp_popup_block').fadeOut(function() {
			jQuery('#sp_fade, a.sp_close').remove();
		});
		return false;
	});

});
