$(document).ready(function() {

	$('.kwicks').kwicks({
        max: 783,
        spacing: 1
    });

    $("a.fancy").fancybox({
		'titleFormat'		: formatTitle,
		'overlayColor'		: '#fff',
		'overlayOpacity'	: '0.5',
		'titlePosition'     : 'over',
		'showCloseButton'   : false,
        'padding'           : 0,
		'autoScale'			: false,
		'onComplete'        : modifyIframe
    });

	$("a.fancy2").fancybox({
		'titleFormat'		: formatTitle,
		'overlayColor'		: '#fff',
		'overlayOpacity'	: '0.5',
		'titlePosition'     : 'over',
		'showCloseButton'   : false,
        'padding'           : 0,
		'autoScale'			: false,
		'onComplete'        : modifyIframe2
    });

	$("a.fancy_point").fancybox({
		'titleFormat'		: formatTitle,
		'overlayColor'		: '#fff',
		'overlayOpacity'	: '0.5',
		'titlePosition'     : 'over',
		//'showCloseButton'   : false,
        'padding'           : 0,
		'onComplete'        : modifyIframe
    });

	$("a.fancy_orige").fancybox({
		//'type'				: 'iframe',
		'autoScale'			: false,
		'titleFormat'		: formatTitle,
		'overlayColor'		: '#fff',
		'overlayOpacity'	: '0.5',
		'titlePosition'     : 'over',
		'showCloseButton'   : false,
        'padding'           : 0,
		'onComplete'        : modifyIframe
    });


	/*$("a.fancy_inline").fancybox({
		'type'				: 'inline',
		'titleFormat'		: formatTitle,
		'overlayColor'		: '#fff',
		'overlayOpacity'	: '0.5',
		'titlePosition'     : 'over',
		'showCloseButton'   : false,
        'padding'           : 0,
		'onComplete'        : modifyIframe
    });*/

	$("#inline").fancybox();



	$("#tabs_container").scrollable().navigator({
		navi: "#tabs",				// select #flowtabs to be used as navigator
		naviItem: 'a',				// select A tags inside the navigator to work as items (not direct children)
		activeClass: 'current',		// assign "current" class name for the active A tag inside navigator
		history: true,				// make browser's back button work
		indexed: true
	});

	// START - scrollable_container
	$(".scrollable_container").scrollable().navigator({
		navi: ".pages",		// select #flowtabs to be used as navigator
		naviItem: 'a',				// select A tags inside the navigator to work as items (not direct children)
		activeClass: 'current',		// assign "current" class name for the active A tag inside navigator
		history: true				// make browser's back button work
	});

	$('.items_pager').width($('.pager').width());
	// END - scrollable_container

	$('.search_top input.search').inputFormat({
		containerClass: 'first',
		preColor: '#555', // default: -
		afterColor: '#B2B2B2', // default: -
		rangeStart: '0', // default: 0
		rangeEnd: '0' // values: numeric number, all; default: 0
		//background: 'true' // default: false
	});

	/*$('select').sSelect({
		scrollHeight: '500px',
		showType: 'hover',
		posX: 0,
		posY: -30
	});*/

	/*
	** start menu_sub position
	**/
	var menuSubLinkWidth = $('.menu_sub_links a.current').width();
	$('.menu_sub_links a.current span').css('left', (menuSubLinkWidth/2)+4+'px');
	// end menu_sub position
});

function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="fancy-title"><a href="javascript:;" onclick="$.fancybox.close();"><img src="/gfx/fancybox/fancy_close.png" border="0" width="15" height="69" class="fancy_close" /></a>' + (title && title.length ? '<span class="title">' + title + '</span>' : '' ) + '</div>';
}

function modifyIframe() {
    Cufon.replace('#fancy-title span.title');
}

function modifyIframe2() {
	$('#fancybox-wrap').css('top', '50px');
    Cufon.replace('#fancy-title span.title');
}

var RecaptchaOptions = new Array ();
RecaptchaOptions['en'] = { lang: 'en', theme: 'red' };
RecaptchaOptions['nl'] = { lang: 'nl', theme: 'red' };
RecaptchaOptions['fr'] = { lang: 'fr', theme: 'red' };
RecaptchaOptions['de'] = { lang: 'de', theme: 'red' };
RecaptchaOptions['pt'] = { lang: 'pt', theme: 'red' };
RecaptchaOptions['ru'] = { lang: 'ru', theme: 'red' };
RecaptchaOptions['es'] = { lang: 'es', theme: 'red' };
RecaptchaOptions['tr'] = { lang: 'tr', theme: 'red' };
RecaptchaOptions['hu'] = { lang: 'hu', theme: 'red', custom_translations: {
	instructions_visual : "Írja be a látottakat:",
	instructions_audio : "Írja be a hallottakat:",
	play_again : "Ismételt lejátszás",
	cant_hear_this : "Nem hallható (MP3 letöltése)",
	visual_challenge : "Szöveges mód",
	audio_challenge : "Felolvasó mód ",
	refresh_btn : "Frissítés",
	help_btn : "Segítség",
	incorrect_try_again : "Hibás! Kérem próbálja újra!"
}};

function changeImg(show,count,nav) {
    var prev1 = document.getElementById('prev1');
    var next1 = document.getElementById('next1');
    var img1 = document.getElementById('influx-image1');
    var img2 = document.getElementById('influx-image2');
    if ( count == '2' ) {
        if ( show == '1' ) {
            img1.style.display = 'block';
            img2.style.display = 'none';
            prev1.style.display = 'none';
            next1.style.display = 'block';
        } else {
            img1.style.display = 'none';
            img2.style.display = 'block';
            prev1.style.display = 'block';
            next1.style.display = 'none';
        }
    } else if ( count == '3' ) {
        var next2 = document.getElementById('next2');
        var prev2 = document.getElementById('prev2');
        var img3 = document.getElementById('influx-image3');
        if ( show == '1' ) {
            img1.style.display = 'block';
            img2.style.display = 'none';
            img3.style.display = 'none';
            prev1.style.display = 'none';
            prev2.style.display = 'none';
            next1.style.display = 'block';
            next2.style.display = 'none';
        } else if ( show == '2' ) {
            img1.style.display = 'none';
            img2.style.display = 'block';
            img3.style.display = 'none';
            prev1.style.display = 'block';
            prev2.style.display = 'none';
            next1.style.display = 'none';
            next2.style.display = 'block';
        } else {
            img1.style.display = 'none';
            img2.style.display = 'none';
            img3.style.display = 'block';
            prev1.style.display = 'none';
            prev2.style.display = 'block';
            next1.style.display = 'none';
            next2.style.display = 'none';
        }
    }
}


function showDesc(index) {
	if (index == 0)	{
		$('.png div').hide();
		$('.png div.coll1').show();
		changeJump(0);

	} else if (index == 1 || index == 2)	{
		$('.png div').hide();
		$('.png div.coll2').show();
		changeJump(1);

	} else if (index == 3 || index == 4) {
		$('.png div').hide();
		$('.png div.coll3').show();
		changeJump(3);

	} else if (index == 5 || index == 6) {
		$('.png div').hide();
		$('.png div.coll4').show();
		changeJump(6);

	} else if (index == 7 || index == 9) {
		$('.png div').hide();
		$('.png div.coll5').show();
		changeJump(8);

	} else if (index == 10 || index == 13) {
		$('.png div').hide();
		$('.png div.coll6').show();
		changeJump(10);
	}
}

function changeJump(index) {
	$('.menu_sub_data a').removeClass('current');
	$('.menu_sub_data #jump'+index).addClass('current');
}

function jumpImg(index) {
	changeJump(index);
	$('#tabs_container').scrollable().seekTo(index);
	showDesc(index);
}

sizeCalc = {

    getWindowWidth: function() {
	    return (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
	},

	getWindowHeight: function() {
	    return window.innerHeight ? window.innerHeight :(document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
	},

	getScrollWidth: function() {
	return document.all ? Math.max(Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth), document.body.scrollWidth) : (document.body ? document.body.scrollWidth : ((document.documentElement.scrollWidth != 0) ? document.documentElement.scrollWidth : 0));
	},

	getScrollHeight: function(){
		body_height = document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0));
		container_height = document.getElementById('reader-container').scrollHeight;
		if (body_height < container_height) return container_height;
		else return body_height;
	},

	getScrollLeft: function() {
		return document.all ? (!document.documentElement.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft) : ((window.pageXOffset != 0) ? window.pageXOffset : 0);
	},

	getScrollTop: function() {
		return document.all ? (!document.documentElement.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop) : ((window.pageYOffset != 0) ? window.pageYOffset : 0);
	},

	getRealHeight: function() {
		return (sizeCalc.getScrollHeight() < sizeCalc.getWindowHeight()) ?  sizeCalc.getWindowHeight() : sizeCalc.getScrollHeight();
	}

}

function changePicMicrosite(id) {
	$('.microsites .micro_item').hide();
	$('.microsites #img'+id).show();

	$('.microsites .menu_right a.link').removeClass('current');
	$('.microsites .menu_right a#link'+id).addClass('current');
}

function changePicAdd(id) {
	$('.add .micro_item').hide();
	$('.add #img'+id).show();

	$('.add .menu_right a.link').removeClass('current');
	$('.add .menu_right a#link'+id).addClass('current');
}

function popup(url,name,width,height,wplus,hplus,focus,left,top,menubar,status,toolbar,scrollbar,resizable,scrx,scry,directories,loc) {
	if ( !url ) return false;
	if ( !name ) name = 'popupWin';
	if ( !width ) width = '';
	if ( !height ) height = '';
	if ( !directories ) directories = 'no';
	if ( !loc ) loc = 'no';
	if ( !menubar ) menubar = 'no';
	if ( !status ) status = 'no';
	if ( !toolbar ) toolbar = 'no';
	if ( !scrollbar ) scrollbar = 'no';
	if ( !resizable ) resizable = 'no';
	if ( !scrx ) scrx = '100';
	if ( !scry ) scry = '100';
	if ( !left ) left = '100';
	if ( !top ) top = '100';
	if ( wplus ) width  += wplus;
	if ( hplus ) height += hplus;

    var popupWin = window.open(url,name,'width='+width+'px,height='+height+'px,left='+left+',top='+top+',menubar='+menubar+',status='+status+',toolbar='+toolbar+',scrollbars='+scrollbar+',resizable='+resizable+',screenX='+scrx+',screenY='+scry+'directories='+directories+',location='+loc);

	if ( focus ) popupWin.focus();
}

