﻿$(document).ready(function() {
	$('ul#largeimages').innerfade({
		animationtype: 'fade',
		speed: 1500,
		timeout: 5000,
		type: 'random_start',
		containerheight: '224px'
	});
	$.googletracklinks("UA-5661758-2");
	$.externallinks();
	$('.profilelist li,.deals li').mouseover(function() {
		$(this).addClass("itemover");
	});
	$('.profilelist li,.deals li').mouseout(function() {
		$(this).removeClass("itemover");
	});

	$('searchbox_005560195576487006702:8004pldc3mc').submit(function() {
		var searchval = $.trim($("#search").val()).toLowerCase();
		var url = "/search/" + searchval;
		pageTracker._trackPageview(url);
		pageTracker._trackEvent('Search', searchval);
		$("#search").attr("title", $("#search").attr("title") + url);
		$("#searchsubmit").attr("title", $("#search").attr("title") + url);
	});
});

$.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);
			$(this).attr("title", $(this).attr("title") + " >");
		}
		else if ($(this).attr("href").match(/^javascript\:emailpage/i)) {
			var url = "/emailpage/" + document.title
			$(this).click(function() {
				pageTracker._trackPageview(url);
				pageTracker._trackEvent('Email Page', document.title);
			})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct);
			$(this).attr("title", $(this).attr("title") + " >>"); // + document.title);
		}
		else if ($(this).attr("href").match(/^javascript\:print/i)) {
			var url = "/print/" + document.title
			$(this).click(function() {
				pageTracker._trackPageview(url);
				pageTracker._trackEvent('Print Page', document.title);
			})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct);
			$(this).attr("title", $(this).attr("title") + " >>>"); // + document.title);
		}
		else if ($(this).attr("href").match(/vcf.asp/i)) {
			var pname = $(this).attr("title").replace(/Download /i, "").replace(/ vCard/i, "")
			var url = "/vcard/" + pname
			$(this).click(function() {
				pageTracker._trackPageview(url);
				pageTracker._trackEvent('Download vCard', pname);
			})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct);
			$(this).attr("title", $(this).attr("title") + " >>>>"); // + pname);
		}
		// Track external links
		else if (location.host != this.host.replace(/\:80$/i, "")) {
			var url = "/outgoing/" + $(this).attr("href").replace(/^http\:\/\/(www\.)*/i, "")
			$(this).click(function() {
				pageTracker._trackPageview(url);
				pageTracker._trackEvent('Outgoing link', $(this).attr("href").replace(/^http\:\/\/(www\.)*/i, ""));
			})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct);
			$(this).attr("title", $(this).attr("title") + " >>>>>"); // + $(this).attr("href").replace(/^http\:\/\/(www\.)*/i, ""));
		}
		// 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");
			if (url_prefix = "http://clients.byteart.com") {
				url_prefix += "/careyolsen2/";
			}
			//var url = '/downloads/' + $(this).attr("href").replace(/^(http\:\/\/)*(www\.)*(careyolsen\.com")*\//i, "");
			var url = '/downloads/' + $(this).attr("rel") + '/' + $(this).attr("title").replace(/ /g, "_");
			$(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", $(this).attr("title") + " >>>>>>");
		}
	});
}

function emailpage() {
	var emailpage = window.open("emailpage.asp?pageurl=" + escape(document.location.href), "emailpage", "width=400,height=350,locationbar=0,menubar=0,personalbar=0,status=0,scrollbars=1,resizable=0");
}

function tracksearch() {
	var searchval2 = $.trim($(".gsc-search-box input:text").val());
	if (searchval2 == "") {
		searchval2 = $.trim($("#search").val());
	}
	$(".gsc-search-box input:text").val(searchval2);
	$("#search").val(searchval2);
	var url = "/search/" + searchval2.toLowerCase();
	pageTracker._trackPageview(url);
	pageTracker._trackEvent('Search', searchval2.toLowerCase());
	$("#search").attr("title", "Search Text: " + url);
}


