﻿url_prefix = "http://www.byteart.com";
//jQuery.noConflict();
//var $j = jQuery;


$(document).ready(function() {
	// validationAide ready
	$('#slide-controls').css("display", "none");
	$('#fedwrk').css("display", "none");
	$("#aspnetForm").validationAideEnable();
	// $("#formtobevalidated").validationAideEnable();
	// hide all <noscript> elements
	$(".NoScript").css('display', 'none');
	$(".scriptNeeded").css('display', 'inline');
	if ($("#BtnSignUp").length != 0) {
		$("#BtnSignUp").empty();
		$("#BtnSignUp").html('<div class="button"><div class="button_text"><a id="BtnSignUp" href="javascript:showSignUpFm()">sign-up</a></div></div>');
	}

	//if($("#BtnShowMap").length != 0) {
	//        htmlBtnShowMap = '<div class="button">';
	//        htmlBtnShowMap += '<a class="text" id="MapBtnTxt" href="Javascript:showMap()">view map</a></div>';
	//        
	//        $("#BtnShowMap").html(htmlBtnShowMap);
	//    }

	$("#site_search").submit(function() {
		var searchstring = $("#site_search").get(0).searchstring.value
		document.location.href = "http://www.byteart.com/search/" + searchstring + "/";
		return true;
	});

	$(".imgsmall").tooltip({
		delay: 0,
		showURL: false,
		bodyHandler: function() {
			var id = this.id;
			if (id.length < 5) {
				return false;
			} else {
				return $("<img/>").attr("src", "/Content/clientlist/" + this.id);
			}
		}
	});

	//$.googletracklinks("UA-1577885-10");
	$.googletracklinks("UA-12855119-1");
	$.externallinks();
});

$.externallinks = function() {
	$('a[href^="http://"]').attr({
		target: "_blank",
		title: function(arr) {
			if ($(this).attr("title").length > 0) {
				$(this).attr("title", $(this).attr("title") + " (opens in a new window)");
			}
			else {
				$(this).attr("title", "opens in a new window");
			}
		}
	});
}

$.googletracklinks = function(_uacct) {
	// The slashes are to ensure the period is in the url, the $ is to make sure it is the end of the url, the i is to make it case insensitive.
	filetypes = /\.doc$|\.xls$|\.exe$|\.zip$|\.pdf$|\.mp3$|\.psd$/i;
	$("a").each(function() {
		// Track mailto links
		if ($(this).attr("href").match(/^mailto\:/i)) {
			var url = "/mailto/" + $(this).attr("href").replace(/^mailto\:/i, "")
			$(this).click(function() {
				pageTracker._trackPageview(url);
				pageTracker._trackEvent('Email Contact', $(this).attr("href").replace(/^mailto\:/i, "").replace(/\;/g, ""));
			})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct);
			if ($(this).attr("title").length > 0) {
				$(this).attr("title", $(this).attr("title") + " >");
			}
			else {
				$(this).attr("title", "Send email to " + $(this).attr("href").replace(/^mailto\:/i, "").replace(/\;/g, ""));
			}
		}
		// Track downloads (links with a given extension)
		else if ($(this).attr("href").match(filetypes)) {
			// The URL needs to be changed for each site this is applied to.
			var url_prefix = String(document.location).replace(/^(https?:\/\/[^:\/]+).*$/, "$1").replace(/^((site)?file:\/\/.+\/)[^\/]+$/, "$1").replace(/(\\.)/g, "\\$1");

			//var url = '/downloads/' + $(this).attr("href").replace(/^(http\:\/\/)*(www\.)*(careyolsen\.com")*\//i, "");
			var url = '/downloads' + $(this).attr("href");
			$(this).attr("rel", url);
			$(this).click(function() {
				pageTracker._trackPageview(url);
				pageTracker._trackEvent('Download', $(this).attr("rel") + ' - ' + $(this).attr("title").replace(/ >>> (opens in a new window)/g, ""));
			})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct + " | " + url_prefix);
			$(this).attr("title", "Download " + $(this).attr("title") + " >>>");
			$(this).attr("target", "_blank");
		}
	});
}





