$(document).ready(function(){

	//toggle menu
	$('a#menulink').livequery(function () {
		$(this).click(function () {
			$('div.main_menu').toggle();
			if ($(this).text() == '>') { ($(this).html("&lt;")); }
			else { ($(this).html("&gt;")); }
		
			$.scrollTo({top:'0px', left:'0px'}, 800, {axis:'xy'});
			return false;
		});
	});
	
	$('a#info').click(function () {
		$('div.gallery#info').toggle();
		$('div.gallery#copyright').hide();
		$('div.gallery#newsletter').hide();
		$.scrollTo({top:'0px', left:'0px'}, 800, {axis:'xy'});
		return false;
	});

	
	$('a.copy').click(function () {
		$('div.gallery#copyright').toggle();
		$('div.gallery#info').hide();
		$('div.gallery#newsletter').hide();
		$.scrollTo({top:'0px', left:'0px'}, 800, {axis:'xy'});
		return false;
	});
	
	
	//newsletter
	$('a#newsletter').click(function () {
		$('div.gallery#newsletter').toggle();
		$('div.gallery#info').hide();
		$('div.gallery#copyright').hide();
		$.scrollTo({top:'0px', left:'0px'}, 800, {axis:'xy'});
		return false;
	});
	

	// toggle galleries links in every categories	
	$('a.catlink').click(function () {
		$('span.catlist:not(#'+$(this).attr('id')+')').hide();
		$('span.catlist#'+$(this).attr('id')).toggle();
		return false;
	});
	

	// toggle the contact card
	$('a#contact_link').click(function () {
		$('div.contact').toggle();
		
					var smalldestination = $('div.contact');
			
			//console.log(smalldestination);
			
			$.scrollTo(
					smalldestination , 
					{ 
						offset:{top:-280, left:-50}, 
						axis:'xy', 
						duration:200, 
						queue:false
					}
				);

		return false;
	});
	
	$('a.gallink').click(function () {

		$.scrollTo({top:'0px', left:'0px'}, 500, {axis:'xy'});
	
		// test if the gallery is allready open
		id = $(this).attr('id'); 
		test = 0;
    
    if ($(this).attr('class') == "gallink") {
    	$(this).addClass('gallink_open');
    } else {
   		$(this).removeClass('gallink_open');
        }

		$('div.gallery').each(function () {
			if ($(this).attr('id') == id) { test = 1;}
		});
		
		if (test == 0) {
			// insert the gallery
			$.get($(this).attr('lll'), function(data){
				$('div#copyright.gallery').after(data);
				$('div.gallery#copyright').hide();
				$('div.gallery#newsletter').hide();
				$('div.gallery#info').hide();
			});
		} else {
			// remove the gallery
			$('div.gallery#'+id).remove();
			$('div.bigger_container#'+id).remove();
		}
		
		//alert('got it');
		//return false;

		// scroll back in place
		//var smalldestination = 'div#top';
		//$.scrollTo('div#top');
		return false;
		
	});
	
	$('a#messit').click(function () {
		$('p').hide();
		$('img:visible').each(function () {
			$(this).css({
				'position':'absolute',
				'top': Math.round($(window).height()/2*Math.random()),
				'left': Math.round($(window).width()/2*Math.random())
			}).show().wrap("<a href='http://vassiliskaridis.com/'></a>");
		});
		return false
	});

	function hide_big (id) {
		$('img.big#'+id).hide();
		$('img.small#'+id).show();
	}

	$('a.image_link img.big').livequery('click', function () {
	
			var smalldestination = $('div#'+$(this).attr('id'));
			
			//console.log(smalldestination);
			
			$.scrollTo(
					smalldestination , 
					{ 
						offset:{top:-280, left:-50}, 
						axis:'xy', 
						duration:200, 
						queue:false
					}
				);
				
			hide_big($(this).attr('id'));
			
			return false;
			
	});
	

	$('a.image_link img.small').livequery(function () {
		$(this).click(
			
			function () {
				var id = $(this).attr('id');
				var proj_id = $(this).parents('.gallery').attr('id');
				//$('img.small#' + id).hide();
				$('img.big#' + id).show();
				var destination = '.big#'+id;

				$.scrollTo(destination, { offset:{top:-280, left:-50}, axis:'xy', duration:200, queue:false });
				$('img.small#' + id).hide();
				//alert('img.big#' + id);
				//console.log('hello world!');
				
				$('img.big#' + id).siblings('.hero').hide();
				
				return false;
			}	
		);
	});



	

 });
