function shareContent(share, url) 
	{
	share_url='';

	a = document.createElement('a');
	a.href = url ? url : document.location.href;

	url_href=a.href;
	url_pathname = a.pathname.indexOf('/')!=0 ? '/'+a.pathname : a.pathname ; /// IE hiba miatti '/' korrekció...
	url_search = a.search;

	share_title = encodeURIComponent('STOP: ' + $("H1").text());

	if (share=='print')
		{
		openwindow('/misc/printpage.php?pageurl='+escape(document.location.pathname)+'&'+document.location.search.substring(1), '720','450', 'yes','yes','yes');
		}
	else if (share=='email')
		{
		openwindow('/misc/sendbyemail.php?pageurl='+escape(document.location.pathname)+'&fullurl='+escape(document.location.pathname+document.location.search)+'&'+document.location.search.substring(1), '480','490','no','sendbyemail');
		}
	else if (share=='facebook')
		{
		share_url='http://www.facebook.com/share.php?u='+escape(url_href);
		}
	else if (share=='twitter')
		{
		share_url='http://twitter.com/home?status=' + share_title + ' ' + escape(url_href);
		}
	else if (share=='linkedin')
		{
		share_url='http://www.linkedin.com/shareArticle?mini=true&title=' + share_title + '&source=STOP&url=' + escape(url_href);
		}
	else if (share=='googleplus')
		{
		share_url='https://m.google.com/app/plus/x/?v=compose&content=' + share_title + ' ' + escape(url_href);
		}
	else if (share=='foursquare')
		{
		share_url='https://foursquare.com/remote_todo?vid=2847885&color=light';
		}
	else if (share=='iwiw')
		{
		share_url='http://iwiw.hu/pages/share/share.jsp?u='+url_href;
		}

	if (share_url) window.open(share_url);
	} 


function openwindow(pageurl,width,height,scroll,winname)
	{
	showscroll=(scroll!='yes' && scroll!=true) ? true : false;
	if (winname=='gallery')
		{
		followVal=false;
		modalColorVal='rgb(92,149,196)';
		opacityVal=1;
		}
	else if (winname=='sendbyemail')
		{
		followVal=false;
		modalColorVal='rgb(0,0,0)';
		opacityVal=0.5;
		}
	else
		{
		followVal=true;
		modalColorVal='rgb(0,0,0)';
		opacityVal=0.5;
		}
	$("#bpopup_popup").html('<iframe src="" width="'+width+'" height="'+height+'" frameborder="no"></iframe><span class="bClose" style="display:none;"></span>');
	$("#bpopup_popup").bPopup({onOpen: function() {$("#bpopup_popup IFRAME").attr('src',pageurl);}, amsl:0, fadeSpeed: 750, scrollBar:showscroll, follow: [followVal,followVal,followVal], followSpeed:100, modalClose:true, modalColor: modalColorVal, opacity: opacityVal});
	}


/// hang, videó és élő adás megjelenítés
function showMedia(objid,id,width,height,type,autostart)
	{
	if (!objid || !id) return;
	width_container = document.getElementById(objid).offsetWidth;
	width_max = 658;
	width_orig = width;
	/// width = width ? width : width_max;
	width = 658; /// legyen mindenképp teljes szélességű
	width = Math.min(width_container, width_max, width);

	height_max = 500;
	height = height ? height : height_max;
	height = Math.round((width/width_orig)*height);
	height = Math.min(height_max, height);

	type = type ? type : 'video';
	th = width + 'x' + height;
	autostart = autostart==null ? true : autostart;

	is_iDevice = (/iPhone|iPod|iPad/i).test(navigator.userAgent); /// iPhone, iPad, iPod detection

	if (type == 'video')
		{
		media_servers = new Array();
		media_servers[0]="mediaserver12_new.quatra.net";
		media_servers[1]="mediaserver13.quatra.net";
		media_server=media_servers[Math.floor(Math.random() * ((media_servers.length -1) + 1))];

		media_path='stop.hu';
		media_file = 'videos/mp4:' + id + '.mp4';
		media_img = '/image/video.php?id=' + id + '&th=' + th;
		
		showlogo = true;
		controlbar = 'over';
		}
	else if (type == 'live')
		{
		media_servers = new Array();
		media_servers[0]="mediaserver12_new.quatra.net";
		media_servers[1]="mediaserver13.quatra.net";
		media_server=media_servers[Math.floor(Math.random() * ((media_servers.length -1) + 1))];

		media_path='live.stop.hu.view';
		media_file = id;
		media_img = '/image/?database_name=live&database_id=' + id + '&th=nh';

		showlogo = true;
		controlbar = 'over';
		}
	else if (type == 'audio')
		{
		media_servers = new Array();
		media_servers[0]="mediaserver12_new.quatra.net";
		media_servers[1]="mediaserver13.quatra.net";
		media_server=media_servers[Math.floor(Math.random() * ((media_servers.length -1) + 1))];

		media_path='stop.hu';
		media_file = 'audios/mp3:' + id + '.mp3';
		media_img = '/images/spacer.gif';

		showlogo = false;
		controlbar = 'bottom';
		}
	else
		{
		return false;
		}

	logo_file=(showlogo ? '/images/stop_logo_small.png' : '');

	jwplayer(objid).setup(
		{
		width: width,
		height: height,
		bufferlength: 2,
		stretching: 'fill',
		controlbar: controlbar,
		'controlbar.margin': 0,
		'controlbar.idlehide': true,
		frontcolor: 'FFFFFF',
		backcolor: '70A2CB',
		lightcolor: 'FFFFFF',
		'logo.file': logo_file,
		'logo.position': 'top-right',
		'logo.out': '1.0',
		'logo.hide': false,
		'logo.link': 'http://www.stop.hu',
		image: media_img,
		modes:
			[
				{
				type: 'flash',   
				src: "/video/player.swf",   
				config:
					{
					autostart: autostart,
					streamer: 'rtmp://' + media_server + '/' + media_path,
					file: media_file,
					provider: 'rtmp'
            		}  
          		},
          		{
          		type: 'html5',
				config:
					{  
					file: (is_iDevice  ?  'http://' + media_server + '/' + media_path + '/_definst_/' + media_file + '/playlist.m3u8'  :  'http://' + media_server.replace(/\D+/i, 'webserver').replace(/\_new/i, '') + '/mediaserver/' + media_path + '/' + media_file.replace(/\/.*\:/i, '/'))
          			}
          		},
				{
				type: 'download',
				config:
					{
					file: 'rtsp://' + media_server + '/' + media_path + '/_definst_/' + media_file
              	} 
				}
     		]
		});
	}


function on_mouse_over() 
	{
	element = eval("document.getElementById('block_share')");
	element.style.visibility = 'visible';
	}

function on_mouse_out() 
	{
	element = eval("document.getElementById('block_share')");
	element.style.visibility = 'hidden';
	}


function showRightTabs(tab_id,box_id)
	{
	$("#box_"+box_id+" > SPAN").hide();
	$("#box_"+box_id+" .boxheader_tabs A").removeClass('tabs_active tabs_nobg');
	$("#box_"+box_id+" #"+tab_id).show();
	$("#box_"+box_id+" #"+tab_id+" .scrollable").trigger('notify', [0]);
	$("#box_"+box_id+" .boxheader_tabs A#tab_"+tab_id).addClass('tabs_active tabs_nobg');
	$("#box_"+box_id+" .boxheader_tabs A#tab_"+tab_id+" + A").addClass('tabs_nobg');
	$("#box_"+box_id+" .boxheader_tabs A:first").addClass('tabs_nobg');
	}


function refreshWeatherRight()
	{
	obj=document.getElementById('cities_weather');
	area_id=obj[obj.selectedIndex].value;
	document.getElementById('cw_area_d').innerHTML=cw_a[area_id];
	document.getElementById('cw_situ_d').src='/images/idojaras/icon_middle_' + cw_s[area_id] + '.png';
	document.getElementById('cw_min_d').innerHTML=cw_min[area_id] + '&deg;C';
	document.getElementById('cw_max_d').innerHTML=cw_max[area_id] + '&deg;C';
	}

function jumptoWeatherPage()
	{
	obj=document.getElementById('cities_weather');
	area_id=obj[obj.selectedIndex].value;
	document.location='/idojaras/?cities_weather='+area_id;
	}

var fontpx = 14;
var minpx = 10;
var maxpx = 20;
function changeFont(dif) 
	{
	var obj;
	var newpx = fontpx + dif;

	if (newpx >= minpx && newpx <= maxpx) 
		{
		obj = document.getElementById("text");
		if (obj) obj.style.fontSize = newpx + "px";
		fontpx = newpx;
		}
	} 


function showGallery(img,database_name,database_id)
	{
	gallery_params=(typeof gallery_params==='undefined') ? '' : gallery_params;

	/// manuálisan meghívva
	if (database_name)
		{
		gallery_url='/gallery/gallery.php?'+gallery_params+'&database_name='+database_name+'&database_id='+database_id;
		}
	/// képre katt
	else
		{
		img=this;

		reg=/(id\=\d+\&ext\=[^&]+|id\=\d+|database_name\=.+\&database_id\=[^&]+)/g;
		imgid=reg.exec(img.src);

		reg2=/(http:\/\/[^\/]+)\//g;
		imgroot=reg2.exec(img.src);

		reg3=/\&type\=([^&]+)/g;
		imgtype=reg3.exec(img.src);
		imgtype=imgtype ? '&type='+imgtype[1] : '';

		if (imgroot[1].indexOf('stop')!=-1) /// saját kép?
			{
			gallery_url='/gallery/gallery.php?'+gallery_params+'&'+imgid[1]+imgtype+(img.src.indexOf('video')!=-1 ? '&media=video' : '');
			imgid=reg.exec(''); /// FF hiba miatt...
			imgroot=reg2.exec(''); /// FF hiba miatt...
			imgtype = reg3.exec(''); /// FF hiba miatt...
			}
		}
	openwindow(gallery_url,1000,695,0,'gallery');
	}


/// egy mérés a tracking iframe segítségével
function track(trackparams)
	{
	trackparams='&database_name='+database_name+'&database_id='+database_id+'&google_code='+encodeURIComponent(google_code)+'&gemius_code='+encodeURIComponent(gemius_code) + ((typeof trackparams==='undefined') ? '' : '&'+trackparams);
	trackurl='/inc/functions/tracking.php?iframe=1' + trackparams + '&rand=' + Math.floor(Math.random()*100000000);
	track_iframe_html='<iframe id="tracking_iframe' + Math.floor(Math.random()*100000000) + '" class="tracking_iframe" src="' + trackurl + '" width="0" height="0" frameborder="no" style="position: absolute; left: -1000px; top: -1000px;"></iframe>';
	$("BODY").append(track_iframe_html);

	/// remove old iframes if more than 25 have been added!
	tracking_iframes = $("IFRAME.tracking_iframe");
	if ($(tracking_iframes).length > 25) $(tracking_iframes).slice(0,1).remove();
	}

zoomimg_timer=0;
img_large_visible=0;
img_dimension_hack=0;

function zoomimg_nu(img,action,e)
	{
	if (action=='toggle') {action=document.img_large_img.src.indexOf('hourglass.gif')==-1 ? 0 : 1;}

	if (action==1)
		{
		zoomimg_nu(null,'cleartimer');
		img_large_visible=1;

		reg=/(id\=\d+\&ext\=[^&]+|id\=\d+|database_name\=.+\&database_id\=[^&]+)/g;
		imgid=reg.exec(img.src);

		reg2=/(http:\/\/[^\/]+)\//g;
		imgroot=reg2.exec(img.src);

		reg3=/\&type\=([^&]+)/g;
		imgtype=reg3.exec(img.src);
		imgtype=imgtype ? '&type='+imgtype[1] : '';
		frames['img_large_frame'].document.location='/image/img_large.php?'+gallery_params+'&img_large_img_src='+escape((imgroot[1] ? imgroot[1] : '')+'/image/?'+imgid[1]+imgtype+'&th=x');
		document.getElementById('img_large').style.display = 'block';

		imgid = reg.exec('');
		imgroot = reg2.exec('');
		imgtype = reg3.exec('');
		}
	/// reposition
	else if (action=='reposition' && img_large_visible)
		{
		zoomimg_nu(null,'cleartimer');

		img_large_obj=document.getElementById('img_large');
		img_large_img_obj=frames['img_large_frame'].document.getElementById('img_large_img');
		iframe_obj=document.getElementById('img_large_frame');

		/// set iframe size, including margins
		if (!img_dimension_hack && !img_large_img_obj.offsetHeight) 
			{
			img_dimension_hack=1;
			img_large_img_obj.src=img_large_img_obj.src;
			}
		
		iframe_obj.height = img_large_img_obj.offsetHeight + (2*20) + 16;
		iframe_obj.width = img_large_img_obj.offsetWidth + (2*20);

		///img_large_obj.style.top = Math.max((parseInt(img_large_obj.style.top) - iframe_obj.height - 25), 160) + 'px';
		scrollposy = window.pageYOffset ? window.pageYOffset : document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop;
		img_large_obj.style.marginTop = (-1 * Math.max((iframe_obj.height/2), 0) + scrollposy) + 'px';
		img_large_obj.style.marginLeft = (-1 * Math.max((iframe_obj.width/2), 0)) + 'px';
		img_large_obj.style.visibility = 'visible';
		}
	/// hide
	else if (action==0 || action==-1)
		{
		if (action==-1 || zoomimg_timer)
			{
			img_large_visible=0;
			zoomimg_nu(null,'cleartimer');

			img_large_obj=document.getElementById('img_large');
			img_large_obj.style.visibility = 'hidden';
			img_large_obj.style.display = 'none';
			///document.img_large_img.src='/images/icons/hourglass.gif';
			}
		else if (img_large_visible)
			{
			zoomimg_timer=setTimeout("zoomimg_nu(null,-1);", 300);
			}
		}
	else if (action=='cleartimer')
		{
		clearTimeout(zoomimg_timer);
		zoomimg_timer=0;
		}


	}

function nopicsave()
	{
	return false;
	}


/// adserver start
function adserver_display_ad(zones_id,banner_txt)
	{
	if (!window.adserver_ads[zones_id])
		{
		window.adserver_ads[zones_id]=banner_txt;
		}
	else
		{
		document.write(window.adserver_ads[zones_id]);
		}
	}
window.adserver_ads=new Array();


/// onload
$(document).ready(function()
	{
	/// a hosszú szövegeket csonkolja
	$(".ellipsis").dotdotdot();

	/// kattinthatóvá teszi a képeket
	$('IMG.showgallery, DIV.img_inline IMG, DIV.img_inline_left IMG, DIV.img_inline_right IMG, DIV.img_inline_center IMG').click(showGallery);

	/// gallery gomb legyen kattintható
	$('IMG#gallerybutton').click(function()
		{
		$("#main_img IMG").click();
		});

	/// régi zoomimg(), hogy ne dobjon hibát ha valahol benne van
	function zoomimg(img,action,e)
		{
		return true;
		}

	/// képeket ne lehessen jobb klikkelni
	$("IMG").bind("contextmenu",function(e)
		{
		return false;
		});

	/// spec select-ek
	$('select').each(function()
		{
		$(this).siblings('span').html($(this).children('option:selected').text());
		$(this).change(function() 
			{
			$(this).siblings('span').html($(this).children('option:selected').text());
			});
		});


	/// scrollozható fresh/top boxok
	$('#box_freshlists .fresh_box').serialScroll(
		{
		items:'.item',
		prev:'#box_freshlists .up_arrow',
		next:'#box_freshlists .down_arrow',
		axis:'y',
		duration:300,
		force:true,
		start:0,
		stop:true,
		lock:false,
		exclude: 5,
		margin: true,
		cycle:false
		});

	/// promo box content_left-ben
	$('#box_promo .promobox').serialScroll(
		{
		items:'.promo_content',
		prev:'#box_promo .left_arrow',
		next:'#box_promo .right_arrow',
		axis:'x',
		duration:1,
		force:true,
		start:0,
		stop:true,
		lock:false,
		margin: true,
		interval:4000,
		cycle:true,
		onBefore:function(e, elem, $pane, $items, pos)
			{
			$('#box_promo .counter').html(pos+1); /// számlaló átírása		
			}
		});

	box_promo_ScrollTimer=null;
	$('#box_promo')
		.mouseenter(function()
			{
			clearTimeout(box_promo_ScrollTimer);
			$('#box_promo .promo_box').trigger('stop');
			})
		.mouseleave(function()
			{
			box_promo_ScrollTimer=setTimeout("$('#box_promo .promo_box').trigger('start')",4000);
			});

	/// foto-video box
	$('#box_foto_video .fotovideo_box').serialScroll(
		{
		items:'.item',
		prev:'#box_foto_video .left_arrow',
		next:'#box_foto_video .right_arrow',
		axis:'x',
		duration:1,
		force:true,
		start:0,
		stop:true,
		lock:false,
		margin: true,
		interval:4000,
		cycle:true,
		onBefore:function(e, elem, $pane, $items, pos)
			{
			$('#box_foto_video .counter').html(pos+1); /// számlaló átírása		
			}
		});

	box_foto_video_ScrollTimer=null;
	$('#box_foto_video #foto, #box_foto_video #video')
		.mouseenter(function()
			{
			clearTimeout(box_foto_video_ScrollTimer);
			$('#box_foto_video .fotovideo_box').trigger('stop');
			})
		.mouseleave(function()
			{
			box_foto_video_ScrollTimer=setTimeout("$('#box_foto_video .fotovideo_box').trigger('start')",4000);
			});
	
	/// 1-esre állítja amikor fület váltunk
	$('#box_foto_video #tab_foto, #box_foto_video #tab_video').click(function()
		{
		$('#box_foto_video .fotovideo_box').trigger('goto', [0]);
		});
	});
