
$(document).ready(function(){

	$('a[href^="http://"]').click( function() {
	
	//$('a[rel="external"]').click( function() {
		window.open(this.href);
		return false;
	});


	$(".open").click(
		function(){
			x = this.id.split("_");
			id = x[1];
			if ( $("#id_" + id).hasClass("close") ){
				$("#id_" + id).removeClass("close");
				$("#news_" + id).slideUp('slow');
				$("#id_" + id).text("részletek >>");
			} else {
//				$(".details").slideUp('slow');
				$(".open").text("részletek >>");
				$(".open").removeClass("close");
				$("#id_" + id).text('becsuk...');
				if ( $("#news_" + id).text() == "" ) {                                                                      
					$("#news_" + id).load("/ajax/getnews.php?i=" + id, function(){ $("#" + this.id).slideDown('slow'); } );
				} else {
					$("#news_" + id).slideDown('slow');
				}
				$("#id_" + id).addClass("close");
				$.scrollTo($("#anchor_" + id),800);
			}
		}   
	);  

	if ( $(".gallery").length > 0 ) {
		Galleria.loadTheme('/js/gallery/themes/classic/galleria.classic.js');
		var hash = getHash();
	}
	
	$('#tabs').tabs({
		selected: hash['t'], 
		select: function(e, ui){
			$("#loadgallery").empty();
			window.location.hash = ui.index;
		}
	});
	
	function getHash() {
		var hash = window.location.hash.substring(1).split("|");
		var h = new Array();
		h['t'] = ( hash[0] ) ? hash[0] : 0;
		h['g'] = ( hash[1] ) ? hash[1] : 0;
		h['i'] = ( hash[2] ) ? hash[2] : 0;
		return h;
	}

	function setHash( k, v ) {
		var hash = getHash();
		hash[ k ] = v;
		window.location.hash = hash['t'] + "|" + hash['g'] + "|" + hash['i'];
	}
	
	function loadgallery(gid, iid){
			$.scrollTo("#loadgallery", 800);
			$("#loadgallery").empty();
			$("#loadgallery").load(
				"/ajax/getgallery.php?i=" + gid,
				function(){
					$('#gallery_' + gid ).galleria({
						thumb_crop: true, // crop all thumbnails to fit
						transition: 'fade', // crossfade photos
						transition_speed: 700, // slow down the crossfade
						show_caption: true,
						debug: true,
						height: 500,
						show: iid,
						data_config: function(img) {
							return  {
								title: $(img).parent().next('strong').html(),
								description: $(img).parent().next('strong').next().html()
							};
						},
						extend: function() {
							this.bind(Galleria.IMAGE, function(e) {
								$(e.imageTarget).css('cursor','pointer').click(this.proxy(function() {
									this.openLightbox();
								}));
							});
							this.bind("loadstart", function(e) {
							    setHash( 'i', e.index );
							});
						}
					})
				}
			);
			setHash( 'g', gid);
	}

	if ( hash['g'] ) {
	    loadgallery(  hash['g'], hash['i'] );
	}

	$(".gallery").click(
		function(e){
			e.preventDefault();
			loadgallery( this.title, 0 );
		}

	);




	$('.email').ready(
	function() {
		var email = $('.email').html();
		if ( email != null ) {
			email = email.replace('(pont)', '.');
			email = email.replace('(kukac)', '@');
			$('.email').html( email );
		}
	}
	);

});
       
       


