var lastDown;
var menuCategoryAnimation = false;
var showSlide = 0;
var slideHold = 5.0;
var slideShowCnt = 0;

function hideEffect( div, params ) {
	params['to'] = 0.1;
	effects = Array( new Effect.Fade( div, params ) );
	if( div == 'main_left' ) {
		effects.push( new Effect.Appear( 'loader' ) );
	}
	new Effect.Parallel( effects );
}

function showEffect( div, params ) {
	params['from'] = 0.1;
	effects = Array( new Effect.Appear( div, params ) );
	if( div == 'main_left' ) {
		effects.push( new Effect.Fade( 'loader' ) );
	}
	new Effect.Parallel( effects );
}

function menuCategoryClicked ( obj ) {
	if( menuCategoryAnimation ) {
		return;
	}
	cnt = obj.id.split( '_' )[2];
	if( cnt == lastDown ) {
		// closing animation
		menuCategoryAnimation = true;
		className = $( 'menu_category_' + lastDown ).className;
		end = className.split( '_' )[2];
		newClassName = className.substring( 0, className.length - end.length ) + 'up';
		$( 'menu_category_' + lastDown ).className = newClassName;
		new Effect.BlindUp( 'menu_category_content_' + lastDown, { 
			duration: 0.5,
			afterFinish: function() {
				menuCategoryAnimation = false;
			}
		} ),
		lastDown = undefined;
		
		
		return;
	}
	menuCategoryAnimation = true;
	
	if( lastDown !== undefined ) {
		className = $( 'menu_category_' + lastDown ).className;
		end = className.split( '_' )[2];
		newClassName = className.substring( 0, className.length - end.length ) + 'up';
		$( 'menu_category_' + lastDown ).className = newClassName;
	}

	className = obj.className;
	end = className.split( '_' )[2];
	newClassName = className.substring( 0, className.length - end.length );
	if( end == 'up' ) {
		newClassName += 'down';
		if( lastDown != undefined ) {
			new Effect.Parallel([
				new Effect.BlindUp( 'menu_category_content_' + lastDown, { duration: 0.5 } ),
				new Effect.BlindDown( 'menu_category_content_' + cnt, {
					duration: 0.5,
					afterFinish: function() {
						menuCategoryAnimation = false;
					}
				} )
			], {
				sync: true
			});
		} else {
			new Effect.BlindDown( 'menu_category_content_' + cnt, { 
				duration: 0.5,
				afterFinish: function() {
					menuCategoryAnimation = false;
				}
			});
		}
	} else {
		newClassName += 'up';
	}
	obj.className = newClassName;
	lastDown = cnt;
}


function showNextSlide( slideShowId ) {
	if( slideShowId == undefined ) {
		slideShowCnt++;
		slideShowId = slideShowCnt;
	} else if( slideShowId != slideShowCnt ) {
		return;
	}
	
	slideshowItems = $$( '.main_slideshow_item' );
	if( slideshowItems.length > 0 ) {
		showSlide++;
	
		width = 631;
		pages = slideshowItems.length;
		showSlide = showSlide % pages;
	
		new Effect.Move( 'box_slideshow_inner2', {
			mode: 'absolute',
			x: ( 0 - showSlide ) * width
		});
	
		showNextSlide.delay( slideHold, slideShowId );
	} else {
		showSlide = 0;
	}
}

function magnifierClicked() {
	Shadowbox.init({ skipSetup: true });
	Shadowbox.open({
		content:    '<div id="map_canvas" style="width: 800px; height: 480px;"></div>',
		player:     "html",
		title:      "Meeting Points",
		width:      800,
		height:     480,
		options: {
			onFinish: function() {
			  var myLatlng  = new google.maps.LatLng(47.500764,19.053125);
			  var myLatlng2 = new google.maps.LatLng(47.49664, 19.050583);
			  var myLatlng3 = new google.maps.LatLng(47.498702, 19.051854);
			  var myOptions = {
				zoom: 15,
				center: myLatlng3,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			  }
			  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
				
			  var marker = new google.maps.Marker({
				  position: myLatlng, 
				  map: map, 
				  title:"Szt. István square - 14.30 tour"
			  }); 

			  var marker2 = new google.maps.Marker({
				  position: myLatlng2, 
				  map: map, 
				  title:"Vörösmarty square - 10.30, 15.30 tours"
			  }); 
  			}
		}
	});
}

function scrollToContent() {
	new Effect.ScrollTo( 'content', { duration: 0.25 } );
}

Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); 
showNextSlide.delay( slideHold );
