
var myTimer = "";
var change = false;
var speed = 2000; 
var interv = 2; //(szünet=sebesség*interv)
var fxs = "fade";
var imagearrobj = new Array();
var imagewrapperobj = new Array();

(function($) {
	var imgList = new Array();
	$.extend({
		preload: function(imgArr, alt, path, option) {
			var setting = $.extend({
				init: function(loaded, total) {},
				loaded: function(img, loaded, total) {},
				loaded_all: function(imgList, loaded, total) {}
			}, option);
			var total = imgArr.length;
			var loaded = 0;
			setting.init(0, total);
			var pid = '';
			for(var i in imgArr) {
				if ( $.browser.msie ) {
					num = Math.random();
					pid = '?preload=' + num ; 
				};
				imgList.push($("<img  />")
					.attr("src", path+imgArr[i]+pid )
					.attr("alt", alt)
					.load(function() {
						loaded++;
						setting.loaded(this, loaded, total);
						if(loaded == total) {
							setting.loaded_all(loaded, total);
						}
					})
				);
			}
			
		}
	});
})(jQuery);
 
function galpreloader(imagewrapper, alt, path, imgFileList) {

	$.preload(imgFileList, alt, path, {
		init: function(){
			$.holdReady(true);
		},
		loaded: function(img, loaded, total) {
			
			imagearrobj.push(img);
			imagewrapperobj.push(''+imagewrapper+'');
			
		},
		loaded_all: function(loaded, total) {
			$.holdReady(false);
		}
	});
};


$(document).ready(function() {


	$(".menu_jegygyuruk.act > img:first").attr('src','img/menu_jegygyuruk-hover.png');
  $(".menu_jegygyuruk").hover(function() {
    $(this).children('img').attr('src','img/menu_jegygyuruk-hover.png');
  },function(){
		if(!($(this).hasClass('act')))
			$(this).children('img').attr('src','img/menu_jegygyuruk.png');
  });	

	
	$('.header ul li span a').css('color','#C1BEB9'); // fix ie html cache bug
	
	/* name of top menu root
	var selected_top_menu = page_link.split("-",1);*/
	
	for(var i in imagearrobj) $(imagewrapperobj[i]).append(imagearrobj[i]);
	$(".slider").show();

		Cufon.replace('.header a', { hover:true });
	if (!( $.browser.msie )) {		
		Cufon.replace('.header', { hover:true });
	};		
		Cufon.replace('.footer', { hover:true });
	

	$(".header ul li").hover(
		function(){ $(this).children("span").show(); },
		function(){ $(this).children("span").hide(); } );

	
	switch (page_id)
	{
	case 44:case 22:
		swfobject.registerObject("videoContent", "9.0.115", "../video/expressInstall.swf");
		swfobject.registerObject("videoContent2", "9.0.115", "../video/expressInstall.swf");
		break;
	case 21:
	case 31: 

		if (!( $.browser.msie )) {
			Cufon.replace('.img_title td', { hover:true }); 
		} else {
			$('.slider img').attr("title","");
		};
		
		/* disable selections */
		disable_selection();

		$(".slider").jCarouselLite({
			btnNext: ".next_image",
			btnPrev: ".prev_image",
			visible: 4.92,
			mouseWheel: true,
			circular: true,
			scroll: 2,
			start: -1.1/*,
			btnGo: thumbarr,*/
		});

		$('.col2 div').each( 
			function() {
				$(this).cycle({
					fx: 'fade',
					speed: speed,
					timeout: speed,
					/*nowrap: 1,*/
					end: function() { /* next_gal(); */}
				}).cycle('pause');
		});
		
		/* change item */
		$('.slider ul li img').click( function() {
		
			window.clearInterval(myTimer);
			/* rotate images */
			var fileprefix = $(this).attr('src').split("/").pop().split("_")[0]; /* kép azonsító előtag */
			var galindex = $("div.gal-rotator img[src*='/"+fileprefix+"_']").parent().index();
			var $gal = $('.col2 div:eq('+galindex+')');
			
			init_hover_gal();
			
			if (!($gal.hasClass("show"))) {
			
				$('.slider ul li').removeClass('act');
				$(this).parent().addClass('act');
				
				/* change images */
				$gal.cycle(0);
				$('.col2 div.show')
				.removeClass('show')
				.stop()
				.cycle('pause')
				.animate({ opacity: 0 },speed/2, function(){ 
					$(this).css({display:'none'}) 
				});
				$gal.stop()
				.addClass('show')
				.css({opacity:0})
				.css({display:'block'})
				.animate({ opacity: 1 },speed/2, function(){ 
					$gal.cycle('resume');
				});
				
				/* change text */
				var img_title = $(this).next("span").html();
				var img_description = $(this).next("span").next("span").html();
				
				if(!(img_title=="")) 
					$('.whitebox')
						.stop()
						.animate({ opacity: 1 },speed/4,
							function(){
								$('.img_title td').html(img_title); 
								$('.img_description td').html(img_description); 
								//Cufon.replace('.img_title td', { hover:true });  IE miatt más egyedi font megoldás kell
								$('.whitebox').animate({ opacity: 0 },speed/4);
								});
			};

		});
	
		
		break;
	case 23:
	case 24:
	case 32:
	case 33:	
	case 34:		
	case 35:		
	case 36:		
	case 42:	
	case 43:	
	case 50:
			disable_selection();
			/* init slider */
			$(".slider").jCarouselLite({
				btnNext: ".next_image",
				btnPrev: ".prev_image",
				visible: 4.92,
				mouseWheel: true,
				circular: true,
				start: -0.1
			});
			$('.gal-rotator').css({display:'block'});
			
			if (page_id!=50) {
				$('.gal-rotator').cycle({ fx: fxs,randomizeEffects: true, speed: speed,timeout: speed,sync: true});
			} else {
				$('.gal-rotator').cycle({ fx: fxs,randomizeEffects: true, speed: speed,timeout: speed, nowrap:true,
				sync: true,	end: function() { $('.gal-rotator').cycle(0).cycle('pause');  }	});
			};
						
			if (page_id==50) { $('.gal-rotator').cycle('pause'); };
			
			$('.slider ul li img').click( function() {
				var fileprefix = $(this).attr('src').split("/").pop().split("_")[0]; /* kép azonsító előtag */
				var imgindex = $(".gal-rotator img[src*='/"+fileprefix+"']").index();
				$('.gal-rotator').cycle(parseInt(imgindex));
				if($(this).attr('src').split("/").pop().substring(0,3)=="0_t") { 
					$('.gal-rotator').cycle(0);
					$('.gal-rotator').cycle('pause'); 
				} else {
					$('.gal-rotator').cycle('resume'); };
			});
			
		break;
	case 41:
		break;
	case 0:
	case 1:
		mainRotator('.col1.rotator','.col2.rotator','.col3.rotator'); 
		break;
	default:
		break;
	};

	/* first click on slider */
	if((page_id==21)&&(gal_id==0)) gal_id = 2;
	if((page_id==31)&&(gal_id==0)) gal_id = 1;
	if((page_id==21)||(page_id==31)) {
	
		$(".slider ul li img[src*='/"+gal_id+"_t']").trigger('click');
		$(".slider ul li img[src*='/"+gal_id+"_t']").parent().addClass('act');
	};
	if(page_id==50) {
		$(".slider ul li img[src*='/0_t']").trigger('click');
	};
	

});







/* -- functions -- */
function mainRotator() { /* alapelve: li a terméken belüi, div a termékek közötti animációt viseli */
	var selector = $.makeArray(mainRotator.arguments);
	for(var coli in selector)	{	
		$(selector[coli]+' .show').css({opacity: 0}).css({display:'block'});
		$(selector[coli]+' .show').stop().animate({ opacity: 1 },speed);	
	}; 
	myTimer = window.setInterval('mainrotate("'+selector.join('","')+'")',speed*interv);
}
function mainrotate() {	
	var selector = $.makeArray(mainrotate.arguments);
	for(var coli in selector) {
		if( !($(selector[coli]).is(":animated").length)) {
			var current = ($(selector[coli]+' ul li.show')?  $(selector[coli]+' ul li.show') : $(selector[coli]+' ul li:first'));
			if ( current.length == 0 ) current = $(selector[coli]+' ul li:first');
			var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $(selector[coli]+' ul li:first') :current.next()) : $(selector[coli]+' ul li:first'));
			next.css({opacity: 0.0})
			.addClass('show')
			.css({display:'block'})
			.stop()
			.animate({opacity: 1.0}, speed);
			current.stop()
			.animate({opacity: 0.0}, speed, function(){ $(this).css({display:'none'}) })
			.removeClass('show');
	};};
};
function disable_selection(){
	$('.prev_image').mousedown(function(){ return false; });
	$('.next_image').mousedown(function(){ return false; });
	$('div').mousedown(function(){ return false; });		
	$('img').mousedown(function(){ return false; });
}
function next_gal() {
	var $current = ($('.col2 div.show') ? $('.col2 div.show') : $('.col2 div:first'));
	if ( $current.length == 0 ) $current = $('.col2 div:first');
	var $next = (($current.next().length) ? (($current.next().hasClass('show')) ? $('.col2 div:first') :$current.next()) : $('.col2 div:first'));	
	gal_id = $next.children('img:first').attr('src').split("/").pop().split("_")[0];
	$(".slider ul li img[src*='/"+gal_id+"_t']").trigger('click');
}
function init_hover_gal(){
		$(".slider ul li img").mousemove(function(e){
			$("#subgal").show();
			$("#subgal").css({
				top: (e.pageY + 20) + "px",
				left: (e.pageX + 0) + "px"
			});
		});
		$(".slider ul li img").mouseout(function(e){
			$("#subgal").hide();
		});
	
		$(".slider ul li img").mouseenter(function(e){
			var fileprefix = $(this).attr('src').split("/").pop().split("_")[0]; /* kép azonsító előtag */
			var galindex = $("div.gal-rotator img[src*='/"+fileprefix+"_']").parent().index();
			$("#subgal").html("<span>"+$(this).attr('alt')+"</span>");
			$('.col2 div:eq('+galindex+') img').clone().prependTo("#subgal");
			$("#subgal img").css({opacity:1});
		});		
}



