<!-- Google Analytics -->
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23023574-1']);
_gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();

function applyAnalytics(url) {
    _gaq.push(['_trackPageview', url]);
    return false;
};
<!-- End Google Analytics -->


jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", "440px");
    this.css("left", ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() - 345 + "px");
    return this;
}

jQuery.fn.doStuff= function(){
	$("#edc").fadeOut(300);
	$("#social").fadeOut(300);
	$("#ecomm").fadeOut(300);
	$("#eq").fadeOut(300);
	$("#esign").fadeOut(300);
	$("#analytics").fadeOut(300);
	$("#hotspots").fadeTo("fast",0)
	$("#iphone").fadeTo("fast",0)
	$("#instructions").fadeTo("fast",0)
	$("a.close").fadeIn(900);
	$("#hs_analytics").css('background','url(images/hs_analytics.png)')
	$("#hs_edc").css('background','url(images/hs_edc.png)')
	$("#hs_eq").css('background','url(images/hs_eq.png)')
	$("#hs_esign").css('background','url(images/hs_esign.png)')
	$("#hs_social").css('background','url(images/hs_social.png)')
	$("#hs_ecomm").css('background','url(images/hs_ecomm.png)')
};

jQuery.fn.slideStuff= function(){
	$("a.close").fadeOut(1);
	$("#edc").slideUp("fast");
	$("#social").slideUp("fast");
	$("#ecomm").slideUp("fast");
	$("#eq").slideUp("fast");
	$("#esign").slideUp("fast");
	$("#analytics").slideUp("fast");
	$("a.close").delay(500).fadeIn(500);
};

$(window).resize(function() {
//	$("#iphone").center();
//	$("#instructions").center();
	$("#interface").center();
});

$(document).ready(function(){

    var url = document.URL; // will be used to set an analytics page url
    // remove the hash at the end of the url
    if (url.substr(url.length-1, 1) == "#") {
        url = url.substr(0, url.length-1);
    }
	var images = ['nav_sub-bg.png','iphone01-ar.png','test-feat_edc.jpg','hs_analytics_o.png','hs_edc_o.png','hs_eq_o.png','hs_esign_o.png','hs_social_o.png','hs_ecomm_o.png'];
	$(images).each(function(key, value) {
		var img = new Image();
		$(img).attr('src', 'images/' + value)
	});

	$("#interface").center();
	$("#iphone").draggable({revert:true}).addTouch();

	$( "#hs_analytics" ).droppable({
		tolerance: 'touch',
		over: function() {
			$(this).css('background','url(images/hs_analytics_o.png)')
		},
		out: function() {
			$(this).css('background','url(images/hs_analytics.png)')
		},
		drop: function( event, ui ) {
			$(this).doStuff();
			$("#analytics").fadeIn(800);
            applyAnalytics(url + "#analytics");
		}
	});
	$("#hs_edc").droppable({
		tolerance: 'touch',
		over: function() {
			$(this).css('background','url(images/hs_edc_o.png)')
		},
		out: function() {
			$(this).css('background','url(images/hs_edc.png)')
		},
		drop: function( event, ui ) {
			$(this).doStuff();
			$("#edc").fadeIn(800);
            applyAnalytics(url + "#edc");
		}
	});
	$("#hs_eq").droppable({
		tolerance: 'touch',
		over: function() {
			$(this).css('background','url(images/hs_eq_o.png)')
		},
		out: function() {
			$(this).css('background','url(images/hs_eq.png)')
		},
		drop: function( event, ui ) {
			$(this).doStuff();
			$("#eq").fadeIn(800);
            applyAnalytics(url + "#eq");
		}
	});
	$("#hs_esign").droppable({
		tolerance: 'touch',
		over: function() {
			$(this).css('background','url(images/hs_esign_o.png)')
		},
		out: function() {
			$(this).css('background','url(images/hs_esign.png)')
		},
		drop: function( event, ui ) {
			$(this).doStuff();
			$("#esign").fadeIn(800);
            applyAnalytics(url + "#esign");
		}
	});
	$("#hs_social").droppable({
		tolerance: 'touch',
		over: function() {
			$(this).css('background','url(images/hs_social_o.png)')
		},
		out: function() {
			$(this).css('background','url(images/hs_social.png)')
		},
		drop: function( event, ui ) {
			$(this).doStuff();
			$("#social").fadeIn(800);
            applyAnalytics(url + "#social");
		}
	});
	$("#hs_ecomm").droppable({
		tolerance: 'touch',
		over: function() {
			$(this).css('background','url(images/hs_ecomm_o.png)')
		},
		out: function() {
			$(this).css('background','url(images/hs_ecomm.png)')
		},
		drop: function( event, ui ) {
			$(this).doStuff();
			$("#ecomm").fadeIn(800);
            applyAnalytics(url + "#ecomm");
		}
	});
	
	$(".home #link-edc").click(function(){ $(this).doStuff(); $("#edc").fadeIn(800); applyAnalytics(url+"#edc"); });
	$(".home #link-social").click(function(){ $(this).doStuff(); $("#social").fadeIn(800); applyAnalytics(url+"#social"); });
	$(".home #link-ecomm").click(function(){ $(this).doStuff(); $("#ecomm").fadeIn(800); applyAnalytics(url+"#ecomm"); });
	$(".home #link-eq").click(function(){ $(this).doStuff(); $("#eq").fadeIn(800); applyAnalytics(url+"#eq"); });
	$(".home #link-esign").click(function(){ $(this).doStuff(); $("#esign").fadeIn(800); applyAnalytics(url+"#esign"); });
	$(".home #link-analytics").click(function(){ $(this).doStuff(); $("#analytics").fadeIn(800); applyAnalytics(url+"#analytics"); });

	$(".home a.close").click(function(){
		$(this).doStuff();
		$("#hotspots").fadeTo("slow",1);
		$("#iphone").fadeTo("fast",1);
		$("#instructions").fadeTo("fast",1);
		$(this).fadeOut(300);
	});

	$(".aboutus #link-edc").click(function(){ $(this).slideStuff(); $("#edc").delay(300).slideDown("slow"); applyAnalytics(url+"#edc"); });
	$(".aboutus #link-social").click(function(){ $(this).slideStuff(); $("#social").delay(300).slideDown("slow"); applyAnalytics(url+"#social"); });
	$(".aboutus #link-ecomm").click(function(){ $(this).slideStuff(); $("#ecomm").delay(300).slideDown("slow"); applyAnalytics(url+"#ecomm"); });
	$(".aboutus #link-eq").click(function(){ $(this).slideStuff(); $("#eq").delay(300).slideDown("slow"); applyAnalytics(url+"#eq"); });
	$(".aboutus #link-esign").click(function(){ $(this).slideStuff(); $("#esign").delay(300).slideDown("slow"); applyAnalytics(url+"#esign"); });
	$(".aboutus #link-analytics").click(function(){ $(this).slideStuff(); $("#analytics").delay(300).slideDown("slow"); applyAnalytics(url+"#analytics"); });
	$(".aboutus a.close").click(function(){ $(this).slideStuff(); });

	$("#topnav li").hover(
		function () {$("ul.sub-menu", this).fadeIn("fast");},
		function () {$("ul.sub-menu", this).fadeOut("fast");}
	);

});
function loadRandomStylesheets(stylesheets)
{
    if(arguments.length < 1) return false;
    var url = arguments[Math.round(Math.random() * (arguments.length - 1))];
    var html = '<style type="text/css">\
                @import url(' + url + ');\
                </style>';
    document.write(html);
    return true;
}
