// Reference for jquery-intellisense:
/// <reference path="~/assets/js/jquery.js" />


// set/empty Search-Textbox
function emptySearchbox(textBoxElement) {
	elementID = "#" + textBoxElement;
	if($(elementID).val() == "Suche") {
		$(elementID).val("");
	}
}

function fillSearchbox(textBoxElement) {
	elementID = "#" + textBoxElement;
	if($(elementID).val() == "") {
		$(elementID).val("Suche");
	}
}

jQuery(document).ready(function () {
	$ = jQuery;
	//  open PopUp-Windows
	$('A[rel="popup"]').click(function () {
		window.open($(this).attr('href'), "popup", "width=480,height=500,toolbar=yes,status=no,directories=no,location=no,menubar=yes,scrollbars=yes,resizable=yes");
		return false;
	});
	//  open PopUp-Windows Ende

	$("#nav ul li").hover(function () {
		$(this).addClass("hover");
		$(this).children("ul").show();
	}, function () {
		$(this).removeClass("hover");
		$(this).children("ul").hide();
	});

	$("table table:odd").addClass("odd");

	$("table.suchergebnis").hover(function () {
		$(this).addClass("hover");
	}, function () {
		$(this).removeClass("hover");
	});

	$("#nav ul li a").focus(function () {
		$(this).parent("li").addClass("hover");
	});

	$(".button").hover(function () {
		$(this).addClass("hover");
	}, function () {
		$(this).removeClass("hover");
	});
});

// nugg.ad I 
var n_pbt = "";

function jump_teaser(selectCtrlId) {
	// 1. Zeichen der URL = boolscher wert, ob link im neuen fenster geöffnet wird
	
	url = $(selectCtrlId).val();
	if (url.substring(0, 1) == '0')
		bolNewWindow = false;
	else
		bolNewWindow = true;

	url = url.substring(1, url.length);
		if (bolNewWindow == true) {
			window.open(url);
		}
		else {
			window.location.href = url;
		}

	//alert("New Window: " + bolNewWindow + "\rUrl: " + url);
}

// PopUp für Stellenanzeigen
function popUpSTM(URL) {
	width = 0;
	height = 0;
	width = Math.ceil(screen.width / 2);
	height = Math.ceil(screen.height * 0.8);
	if (width < 760) width = 760;
	if (height < 480) height = 480;
	left = ((screen.availWidth - width) / 2) - (screen.width - screen.availWidth);
	oben = ((screen.availHeight - height) / 2) - (screen.height - screen.availHeight);
	uebersicht = window.open(URL, 'Detailansicht', 'dependent=yes,titlebar=yes,toolbar=no,status=no,menubar=no,location=no,hotkeys,directories=no,resizable=yes,scrollbars=yes,height=' + height + ',width=' + width + ',left=' + left + ',top=' + oben);
	uebersicht.focus();
}

// google analytics
var gaKey;

switch (document.location.host)
{
	case 'ingenieurkarriere.de':
	case 'www.ingenieurkarriere.de':
	case 'cms.ingenieurkarriere.de':
	case 'ingenieurkarriere.beta.eoa.de':
		gaKey = 'UA-27095315-2';
		break;
	case 'vdi-nachrichten.com':
	case 'www.vdi-nachrichten.com':
	case 'cms.vdi-nachrichten.com':
	case 'vdi-nachrichten.beta.eoa.de':
		gaKey = 'UA-27095315-3';
		break;
	case 'vdi-verlag.de':
	case 'www.vdi-verlag.de':
	case 'cms.vdi-verlag.de':
	case 'vdi-verlag.beta.eoa.de':
		gaKey = 'UA-27095315-4';
		break;
	case 'ingenieur.de':
	case 'www.ingenieur.de':
	case 'cms.ingenieur.de':
	case 'ingenieur.beta.eoa.de':
		gaKey = 'UA-27095315-5';
		break;
	case 'technischeprodukte.de':
	case 'www.technischeprodukte.de':
	case 'cms.technischeprodukte.de':
	case 'technischeprodukte.beta.eoa.de':
		gaKey = 'UA-27095315-6';
		break;
	case 'technical-news.de':
	case 'www.technical-news.de':
	case 'cms.technical-news.de':
	case 'technical-news.beta.eoa.de':
		gaKey = 'UA-27095315-7';
		break;
	default:
		gaKey = '';
		break;
}

if (!gaKey == '')
{
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', gaKey]);
	_gaq.push(['_gat._anonymizeIp']);
	_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 recordOutboundLink(link, category, action) {
		try {
			var myTracker = _gat._getTrackerByName();
			_gaq.push(['myTracker._trackEvent', ' + category + ', ' + action + ']);
		} catch (err) { }
	}

	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

	//	var pageTracker = _gat._getTracker(gaKey);
	//	pageTracker._trackPageview();

	var downloadExtension = new Array('doc', 'docx', 'pdf', 'xls', 'ppt', 'zip', 'gz', 'bz2', 'rar', 'txt', 'vsd', 'vxd', 'js', 'css', 'exe', 'wma', 'mov', 'avi', 'wmv', 'mp3', 'mp4');
	var trackDownloadsAsEvent = false;
	var trackExtlinksAsEvent = true;
	var downloadCat = 'Downloads';
	var extLinksCat = 'Externe Links';
	var intDomain = window.location.hostname;

	if (window.addEventListener) {
		document.addEventListener('click', clickHandler, false);
	}
	else {
		document.attachEvent('onclick', clickHandler);
	}

	function clickHandler(e) {
		if (window.event) e = window.event;
		var srcEl = e.srcElement ? e.srcElement : e.target;
		var targetUrl = srcEl.getAttribute('href');
		if (targetUrl && targetUrl.length > 0) {
			var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');
			var tarDomain = (targetUrl.match(re) ? targetUrl.match(re)[1].toString() :
			 (targetUrl.indexOf(':') < 0 ? intDomain : null));
			if (tarDomain != null) {
				var a = document.createElement('a');
				a.href = targetUrl;
				var filePath = a.pathname;
				var fileName = filePath.split('/').pop();
				var fileExt = fileName.substring(fileName.indexOf('.') + 1);
				if (intDomain == tarDomain) {
					for (i = 0; i < downloadExtension.length; i++) {
						if (fileExt == downloadExtension[i]) {
							if (trackDownloadsAsEvent) _gaq.push(['_trackEvent', downloadCat, filePath]);
							else _gaq.push(['_trackPageview', filePath]);
						}
					}
				}
				else {
					if (trackExtlinksAsEvent) _gaq.push(['_trackEvent', extLinksCat, tarDomain]);
					else _gaq.push(['_trackPageview', '/' + extLinksCat + '/' + tarDomain]);
				}
			}
		}
	}
}
