function a() {
	if ($.browser.msie) {
		var f = $(document).height(),
		e = $(window).height();
		return [$(window).innerWidth || document.documentElement.clientWidth || document.body.clientWidth, f - e < 20 ? e: f]
	}
	return [$(window).width(), $(document).height()]
}
function nav_bg() {
	$('#nav-top li:not(.sfHover) a.tab:not(.active)').stop().animate({backgroundPosition:"(0px 15px)"}, {duration:200, complete:function(){
					$(this).css({backgroundPosition: "0 15px"})
	}})
}
var b;
$(document).ready(function() { 
	$('ul#nav-top').superfish({ 
		delay:       500,                            // 0.5 second delay on mouseout 
		animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
		speed:       'fast',                          // faster animation speed 
		autoArrows:  false,                           // disable generation of arrow mark-up 
		dropShadows: false,                            // disable drop shadows 
		onHide: nav_bg
	});
	b = a();
	$('#nav-top a.tab:not(.active)')
		.css( {backgroundPosition: "0 15px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-154px 15px)"}, {duration:500})
		})
		.mouseout(function(){
			if ($(this).parents("li.sfHover")) {
			} else {
				$(this).stop().animate({backgroundPosition:"(0px 15px)"}, {duration:200, complete:function(){
					$(this).css({backgroundPosition: "0 15px"})
				}})
			}
	});
	$("#masterplan_button a").click(function(){
		if($(this).hasClass("active")) {
			$(this).removeClass("active");
			$("#ssp").show();
		} else {
			$(this).addClass("active");
			$("#ssp").hide();
		}
		$('#masterplan_overlay').css("height",b[1]-116).animate({width:'toggle'});
		return false;
	});
	$(window).resize(function() {
		b = a();
		$('#masterplan_overlay').css("height",b[1]-116);
	});
	$("#subscribeform").validate({
        invalidHandler : function(form, validator) {
            var elements = $('input[type=text], textarea');
            $.each(elements, function(i, element) {
			   if($(elements[i]).val() == "") {
				   $(elements[i]).addClass('silver').val($(elements[i]).attr("rel"));
			   }
            });
        }
	});
	$("input, textarea").focus(function(){
		if ( $(this).hasClass("silver") ) {
			$(this).removeClass("silver").val("");
		}
	});
	$("input, textarea").blur(function(){
		if ( $(this).val() == "" ) {
			$(this).addClass("silver").val($(this).attr("rel"));
		}
	});
	$(".btn-send").click(function(){
		$(this).parents("form").find("input:not(.ignore)[type=text], textarea").each(function(e){
			if ( $(this).hasClass("silver") ) {
				$(this).removeClass("silver").val("");
			}
		});
		$(this).fadeOut("fast").parents("form").submit();setTimeout('$(".btn-send").show();',2000);return false;
	});
    $("#masterplan_overlay area").hover(
	function() {
        $("img.masterplan_bg").hide();
        $("#" + $(this).attr('class')).show();
    },
	function() {
        $("img.masterplan_bg").hide();
    });
});
(function($){var $liveTip=$('<div id="livetip"></div>').hide().appendTo('body'),$win=$(window),showTip;var tip={title:'',offset:12,delay:300,position:function(event){var positions={x:event.pageX,y:event.pageY};var dimensions={x:[$win.width(),$liveTip.outerWidth()],y:[$win.scrollTop()+$win.height(),$liveTip.outerHeight()]};for(var axis in dimensions){if(dimensions[axis][0]<dimensions[axis][1]+positions[axis]+this.offset){positions[axis]-=dimensions[axis][1]+this.offset;}else{positions[axis]+=this.offset;}}
$liveTip.css({top:positions.y,left:positions.x});}};$('body').delegate('a, input, select, textarea, label, p','mouseover mouseout mousemove',function(event){var link=this,$link=$(this);if(event.type=='mouseover'){tip.title=link.title;link.title='';if(tip.title.length>1){showTip=setTimeout(function(){$link.data('tipActive',true);tip.position(event);$liveTip.html('<div class="qtip-content">'+tip.title+'</div>').fadeOut(0).fadeIn(200);},tip.delay);}}
if(event.type=='mouseout'){link.title=tip.title||link.title;if($link.data('tipActive')){$link.removeData('tipActive');$liveTip.hide();}else{clearTimeout(showTip);}}
if(event.type=='mousemove'&&$link.data('tipActive')){tip.position(event);}});})(jQuery);

(function($) {
    var $areaTip = $('<div id="areaTip"></div>').hide().appendTo('body'),
    $win = $(window),
    showTip;
    var tip = {
        alt: '',
        offset: 12,
        delay: 300,
        position: function(event) {
            var positions = {
                x: event.pageX,
                y: event.pageY
            };
            var dimensions = {
                x: [$win.width(), $areaTip.outerWidth()],
                y: [$win.scrollTop() + $win.height(), $areaTip.outerHeight()]
            };
            for (var axis in dimensions) {
                if (dimensions[axis][0] < dimensions[axis][1] + positions[axis] + this.offset) {
                    positions[axis] -= dimensions[axis][1] + this.offset;
                } else {
                    positions[axis] += this.offset;
                }
            }
            $areaTip.css({
                top: positions.y,
                left: positions.x
            });
        }
    };
    $('body').delegate('area', 'mouseover mouseout mousemove',
    function(event) {
        var link = this,
        $link = $(this);
        if (event.type == 'mouseover') {
            tip.alt = $('#'+$(this).attr('class')+'_tip').html();
            link.alt = '';
            if (tip.alt.length > 1) {
                showTip = setTimeout(function() {
                    $link.data('tipActive', true);
                    tip.position(event);
                    $areaTip.html('<div class="qtip-content">' + tip.alt + '</div>').fadeOut(0).fadeIn(200);
                },
                tip.delay);
            }
        }
        if (event.type == 'mouseout') {
            if ($link.data('tipActive')) {
                $link.removeData('tipActive');
                $areaTip.hide();
            } else {
                clearTimeout(showTip);
            }
        }
        if (event.type == 'mousemove' && $link.data('tipActive')) {
            tip.position(event);
        }
    });
})(jQuery);
