﻿function stop(e) {
	if (!e) e = window.event;
	(e.stopPropagation) ? e.stopPropagation() : e.cancelBubble = true;
	(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
	return false;
}

function prevDef(e) {
	if (!e) e = window.event;
	(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
	return false;
}  

function log(message) {
	if (typeof console != 'undefined' && typeof console.log != 'undefined') {
		console.log(message);
	}
};

jQuery.noConflict();
jQuery(document).ready(function(){
	jQuery("body").removeClass("noJs").addClass("activeJs");
	if (jQuery('.print').length != 0) {jQuery('.print').printButton();}
	if (jQuery('#en_sites').length != 0) {initLanguageBox();}
	initGA(); 
	initSite(); //initialize the site-specific js functions
});

function initGA() { //Google Analytics
	
	//custom jquery filters 
	//based on http://neutroncreations.com/blog/how-to-track-traffic-exiting-your-site/
	
	//external links 
	var topdomain = ".hu."; //leave empty if your site doesn't use subdomains
	jQuery.expr[':'].external  = function(obj){
		if (topdomain != "") {
			return !obj.href.match(/^mailto:/) && !obj.href.match(/^javascript:/)
			&& ((obj.hostname != document.location.hostname)&&!(obj.hostname.indexOf(topdomain)>-1));
		}
		else {
			return !obj.href.match(/^mailto:/) && !obj.href.match(/^javascript:/)
			&& (obj.hostname != document.location.hostname);
		}
	};
	
	//_trackEvent(category, action, opt_label, opt_value)
	jQuery('a:external').click(function(){
		if (typeof _gaq != 'undefined') {
			_gaq.push(['_trackEvent','Hyperlinks','Clicked '+jQuery(this).attr('href'),'External link']);
		}
		else {
			log("no tracking code found");
		}
	});    
	    
}

//init english site listing pop-up
	function initLanguageBox() {

		var target = jQuery('#toplinks-one');

		target.css({
			backgroundColor: "transparent",
			backgroundImage: "url('/includes/img/HU-GLOBAL/bg-lang-but-up.png')",
			backgroundPosition: "top right",
			backgroundRepeat: "no-repeat"
		});

		jQuery('#en_sites', target).hide().css({ position: 'absolute', right: '1px', top: '19px' });
		jQuery('#english').attr('href', 'javascript:void(0)').toggle(
	        function() {
	        	jQuery(this).next().slideDown()
	        	target.css({ backgroundImage: "url('/includes/img/HU-GLOBAL/bg-lang-but-down.png')" });
	        },
	        function() {
	        	jQuery(this).next().slideUp()
	        	target.css({ backgroundImage: "url('/includes/img/HU-GLOBAL/bg-lang-but-up.png')" });
	        }
	    );
	
	}