﻿/* preset */
var oID = document.getElementById;
var IE = /*@cc_on!@*/false;
var IE6 = (IE && (navigator['appVersion'].indexOf('MSIE 6') > 0)) ? true : false;
/* /preset */
var bannerClickUrl = "";

/* event handlers */
function addEvent(o, sEvent, fFunc) {
	if (window.attachEvent) {
		o.attachEvent('on' + sEvent, fFunc);
	} else if (window.addEventListener) {
		o.addEventListener(sEvent, fFunc, false);
	}
}

function addLoadEvent(fFunc) {
	addEvent(window, 'load', fFunc);
}

function addDOMLoadEvent(func) {
	if (!window.__load_events) {

		var init = function () {
			if (arguments.callee.done) return; // quit if this function has already been called
			arguments.callee.done = true; // flag this function so we don't do the same thing twice
			if (window.__load_timer) { // kill the timer
				clearInterval(window.__load_timer);
				window.__load_timer = null;
			}
			for (var i=0; i<window.__load_events.length; i++) { // execute each function in the stack in the order they were added
				window.__load_events[i]();
			}
			window.__load_events = null;
		};

		// for Mozilla/Opera9
		if (document.addEventListener) {
			document.addEventListener('DOMContentLoaded', init, false);
		}

		// for Internet Explorer
		/*@cc_on @*/
		/*@if (@_win32)
			document.write('<scr'+'ipt id=__ie_onload defer src=//0><\/scr'+'ipt>');
			var script = document.getElementById('__ie_onload');
			script.onreadystatechange = function() {
				if (this.readyState == 'complete') {
					init(); // call the onload handler
				}
			};
		/*@end @*/

		// for Safari
		if (/WebKit/i.test(navigator.userAgent)) { // sniff
			window.__load_timer = setInterval(function() {
				if (/loaded|complete/.test(document.readyState)) {
					init(); // call the onload handler
				}
			}, 10);
		}

		// for other browsers
		window.onload = init;

		// create event function stack
		window.__load_events = [];
	}

	// add function to event stack
	window.__load_events.push(func);
}
/* /event handlers */



/* QWEswfobj */
// disable the blinking when set outerHTML, may need to load external css file, where only flash objects have display: none property
if (IE) document.writeln('<style type="text/css">object {display: none;}</style>');
// rewrite satay swf objects
function QWEswfobj() {
	var swf = '';
	var obj = document.getElementsByTagName('object');
	for (var i=0; i<obj.length; i++) {
		if ((obj[i].getAttribute('type') == 'application/x-shockwave-flash') || (obj[i].getAttribute('classid') == 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000')) {
			swf = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
			swf += (obj[i].getAttribute('id')) ? ' id="' + obj[i].getAttribute('id') + '"' : '';
			swf += (obj[i].getAttribute('width')) ? ' width="' + obj[i].getAttribute('width') + '"' : '';
			swf += (obj[i].getAttribute('height')) ? ' height="' + obj[i].getAttribute('height') + '"' : '';
			swf += '>' + "\n";
			for (var j=0; j<obj[i].childNodes.length; j++) {
				if ((obj[i].childNodes[j].nodeName) && (obj[i].childNodes[j].nodeName.toLowerCase() == 'param')) {
					swf += '<param name="'+obj[i].childNodes[j].getAttribute('name')+'" value="'+obj[i].childNodes[j].getAttribute('value')+'" />'+"\n";
				} else if ((obj[i].childNodes[j].nodeName) && (obj[i].childNodes[j].nodeName.toLowerCase() == 'div')) {
					swf += '<div>' + obj[i].childNodes[j].innerHTML + '</div>' + "\n";				
				}
			}
			swf += '</object>'+"\n";
			obj[i].outerHTML = swf;
		}
		obj[i].style.display = 'block';
	}
}
/* /QWEswfobj */



/* get elements by className */
getElementsByClassName = function(parentNode, className) {
	var result = [];
	if (!className) {
		if (typeof(parentNode) == 'string') {
			var className = parentNode;
			parentNode = document;
		} else {
			return result;
		}
	}
	var obj = parentNode.getElementsByTagName('*');
	for (var i=0; i<obj.length; i++) {
		if (obj[i].className.match(new RegExp('\\b' + className + '\\b'))) {
			result.push(obj[i]);
		}
	}
	return result;
}
/* /get elements by className */



/* get style */
function getStyle(obj, styleProp) {
	var result = (window.getComputedStyle) ? document.defaultView.getComputedStyle(obj, null).getPropertyValue(styleProp) : ((obj.currentStyle) ? obj.currentStyle[styleProp] : '');
	if (result.indexOf('rgb') >= 0) {
		var h = '0123456789abcdef';
		var d = result.split('rgb(')[1].split(')')[0].split(' ').join('').split(',');
		result = '#' + h[d[0] >> 4] + h[d[0] % 16] + h[d[1] >> 4] + h[d[1] % 16] + h[d[2] >> 4] + h[d[2] % 16];
	}
	return result;
}
/* /get style */



/* :hover */
function hover(obj) {
	obj.onmouseover = function() {
		this.className += ' hover';
	}
	obj.onmouseout = function() {
		this.className = this.className.split('hover').join('');
	}
}
/* /:hover */



/* show picture in popup */
var popup = null;
function showpic(pic, label, w, h) {
	if ((popup) && (!popup.closed)) {
		popup.close();
	}
	popup = window.open('','popup','directories=0,location=0,menubar=0,personalbar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,width='+String(w)+',height='+String(h)+',left='+String(Math.floor((screen.width-w)/2))+',top='+String(Math.floor((screen.height-h)/2)-22));
	with (popup.document) {
		open('text/html');
		writeln('<html>');
		writeln('<head>');
		writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
		writeln('<title>' + ((label != '') ? label + ' ' : '') + '</title>');
		writeln('<style>');
		writeln('html, body {margin: 0px; padding: 0px; background-color: #666; overflow: hidden;}');
		writeln('a, img {display: block; border: none 0px; margin: 0px; padding: 0px;}');
		writeln('</style>');
		writeln('</head>');
		writeln('<body>');
		writeln('<a href="javascript:;" onclick="self.close();"><img src="'+pic+'" alt="' + ((label != '') ? label + ' ' : '') + '" /></a>');
		writeln('</body>');
		writeln('</html>');
		close();
	}
	popup.focus();
}
/* /show picture in popup */



/* printable version */
function printToggle() {
	var head = document.getElementsByTagName('head')[0];
	if (!head['ps']) {
		var ps = document.createElement('link');
		head['ps'] = ps;
		ps.setAttribute('type', 'text/css');
		ps.setAttribute('href', '/css/printscreen.css');
		//ps.setAttribute('href', '/css/print.css');
		
		ps.setAttribute('rel', 'stylesheet');
		ps.setAttribute('media', 'screen');
		head.appendChild(ps);
		var pb = document.createElement('div');
		pb.className = 'printscreen';
		pb.innerHTML = '<input type="button" value="&laquo; vissza" onclick="printToggle(); return false;" /> <input type="button" value="nyomtatás" onclick="window.print(); return false;" />';
		document.body.insertBefore(pb, document.getElementsByTagName('form')[0]);
	} else {
 		$("printscreen").visible = false;
		if (head['ps'].getAttribute('rel').indexOf('alt') < 0) {
			head['ps'].setAttribute('rel', 'alternate stylesheet');
			head['ps'].disabled = true;
		} else {
			head['ps'].setAttribute('rel', 'stylesheet');
			head['ps'].disabled = false;
		}
		
	}
}

function setActiveStyleSheet(title) {  var i, a, main;  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {      a.disabled = true;      if(a.getAttribute("title") == title) a.disabled = false;    }  }}
/* /printable version */



/* show picture in popup */
var popup = null;
function showpic(pic, label, w, h) {
	var resize = false;
	var wh = [screen.width-64, screen.height-64];
	if ((w > wh[0]) || (h > wh[1])) {
		w = (h > wh[1]) ? Math.min(w, wh[0])+20 : Math.min(w, wh[0]);
		h = (w > wh[0]) ? Math.min(h, wh[1])+20 : Math.min(h, wh[1]);
		resize = true;
	}
	if ((popup) && (!popup.closed)) {
		popup.close();
	}
	popup = window.open('','popup','directories=0,location=0,menubar=0,personalbar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,width='+String(w)+',height='+String(h)+',left='+String(Math.floor((screen.width-w)/2))+',top='+String(Math.floor((screen.height-h)/2)-22));
	with (popup.document) {
		open('text/html');
		writeln('<html>');
		writeln('<head>');
		writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
		writeln('<title>' + ((label != '') ? label + ' ' : '') + '</title>');
		writeln('<style>');
		writeln('html, body {margin: 0px; padding: 0px; background-color: #333;' + ((resize) ? '' : ' overflow: hidden;') + '}');
		writeln('div, a, img {display: block; border: none 0px; margin: 0px; padding: 0px;}');
		writeln('</style>');
		writeln('</head>');
		writeln('<body>');
		writeln('<a href="javascript:;" onclick="self.close();"><img src="'+pic+'" alt="' + ((label != '') ? label + ' ' : '') + '" /></a>');
		writeln('</body>');
		writeln('</html>');
		close();
	}
	popup.focus();
}
/* /show picture in popup */



/* initialization */
function DOMLoadInit() {

	// execute QWEswfobj in IE
	if (IE) QWEswfobj();

	if (IE6) {
		var menu = document.getElementById('menu');
		if (menu!=null)
		{ 
		    var li = menu.getElementsByTagName('li');
		    for (var i=0; i<li.length; i++) {   
			    if (li[i].className.indexOf('mm') >= 0) {hover(li[i]);}
		    }
		}
	}

	var input = document.getElementsByTagName('input');
	for (var i=0; i<input.length; i++) {
		if (IE6 && (input[i].parentNode.className.indexOf('submit') >= 0)) {hover(input[i]);}
		if (input[i].getAttribute('type').indexOf('hidden') >= 0 ) {input[i].className = 'hidden';}
	}

	/* modify links */
	var a = document.getElementsByTagName('a');
	for (var i=0; i<a.length; i++) {
		/* target="_blank" */
		if (a[i].className.indexOf('_blank') >= 0) {
			a[i].onclick = function() {
				this.blur();
				window.open(this.href);
				return false;
			}
		}
		/* /target="_blank" */
		/* popup image */
		if (a[i].className.indexOf('_popup') >= 0) {
			a[i].label = a[i].title;
			a[i].title = '';
			a[i].onclick = function() {
				this.blur();
				var wh = this.className.split('_popup(')[1].split(')')[0].split(',');				
				showpic(this.href, this.label, parseInt(wh[0], 10), parseInt(wh[1], 10));
				return false;
			}
		}
		/* /popup image */
	}
	/* /modify links */
	if (bannerClickUrl)
	{
	    $("div.PAGE div#flashobject").bannerCatchClick(bannerClickUrl,bannerClickNewWindow);
	}
}

$.fn.bannerCatchClick = function(u,w) {
	var that = $(this);
	that.find("embed, object, img").each(function(){
		$(this).attr({ wmode: "transparent" }).css({ zIndex: 100, position: "absolute" }).before('<div class="catchclick" style="width: '+$(this).width()+'px; height: '+$(this).height()+'px;"></div>');
		$("div.catchclick").click(function(){ if (w===true) { window.open(u); } else { self.location=u; } });

	});
// }); });
}

function onLoadInit() {
}

addDOMLoadEvent(DOMLoadInit);

addLoadEvent(onLoadInit);
/* /initialization */


$.fn.extend({

	fancyflash: function() {
		var mediaUrl = $(this).attr('params');
		var rootUrl = "http://"+(document.location+"").split("/")[2];

		var fancyParams = ($(this).attr('href')+'#').split('#')[1].split('_');
		var fancyType = fancyParams[0];
		
		if (fancyType=="TvSpot") {
			var fancyWidth = 400;
			var fancyHeight = 300;
			var fancyMedia = "video";
		}
		
		if (fancyType=="RadioSpot") {
			var fancyWidth = 400;
			var fancyHeight = 20;
			var fancyMedia = "sound";
		}
		
		//Ez csak dummy, a flasht megjeleniteskor irjuk kozvetlenul a fancy_div-be;
		$(this).attr('href', '#swfcontainer');
		
		$(this).fancybox({
			zoomSpeedIn: '2000',
			zoomSpeedOut: '2000',
			overlayOpacity: '0.5',
			frameWidth : fancyWidth,
			frameHeight : fancyHeight,
			centerOnScroll: false,
			callbackOnShow : function() {
				var so = new SWFObject(rootUrl+"/swf/player.swf", "swfcontent", fancyWidth, fancyHeight, "9", "#f0f0f0");
				so.addParam("allowfullscreen","true");
				so.addParam("allowscriptaccess","always");
				so.addParam("flashvars","type="+fancyMedia+"&file="+rootUrl+mediaUrl);
   				so.write("fancy_div");
			}
		});		
		
	}
			
});

$(function() {
		   
	$('a.fancybox').each(function(){
								  
		if ($(this).closest("div.item").hasClass("TvSpot") || $(this).closest("div.item").hasClass("TvSpot")) {
			$(this).fancyflash();
		} else {
			$(this).fancybox({
				zoomSpeedIn: '2000',
				zoomSpeedOut: '2000',
				overlayOpacity: '0.5',
				centerOnScroll: false,
				hideOnContentClick: false
			 });
		}
	});
	
	$('a.fancyflash').each(function() {
		$(this).fancyflash();	
	});
	
	$("div.slideshow a").fancybox();
	
		
});
