$(document).ready(function ()
{
	jQuery.ifixpng('i/s.gif');
	jQuery('img, .bgPng').ifixpng();
	jQuery('td, .bgPng').ifixpng();
	jQuery('div, .bgPng').ifixpng();
	jQuery('a, .bgPng').ifixpng();
	jQuery('li, .bgPng').ifixpng();
	jQuery('body, .bgPng').ifixpng();
});
	
$(function(){

	$("#full-image .close a").click(function(e){
		e.preventDefault()
		$("#full-image").fadeOut("fast");
	})
	//var s,next,prev,f,i,current,total,relW,relH,c;
	
	$(".full-gallery").click(function(e){
		e.preventDefault()

		$s=$(this).index(".full-gallery");
		$next=$(".full-gallery:eq("+($s+1)+")");
		$prev=$(".full-gallery:eq("+($s-1)+")");

		$f=$("#full-image");
		$f.find("#main").remove();
		
		$i=$(this);
		
		$f.fadeIn("fast");
		$f.find(".title").html($(this).attr("alt"));
		
		$current=$s+1;
		$total=$(".full-gallery").size();
		
		$f.find("span#current").html($current);
		$f.find("span#total").html($total)

		$relW=parseInt($i.attr("relW"));
		$relH=parseInt($i.attr("relH"));
		$c=$relW/$relH;

		if($relW>=$relH)
		{
			if($relW>$(window).width()-300)
			{
				$relW=$(window).width()-300;	
				$relH=Math.ceil($relW/c);
			}
		}
		else if($relW<$relH)
		{
			if($relH>$(window).height()-300)
			{
				$relH=$(window).height()-300;
				$relW=Math.ceil($relH*c);
			}
		}
		$f.find(".pb10").append('<img src="/i/s.gif" width="300" height="300" id="main" />');
		$f.find("table").css({"width":$relW});
		$f.find("#main").attr("src", $i.closest("a").attr("href")).css({
			width:$relW,
			height:$relH
		})

		if($prev.length>0)
		{
			$f.find(".prev-photo").unbind().show().click(function(e){
				e.preventDefault();
	
				$prev.trigger("click");
			})
		}
		else
			$f.find(".prev-photo").hide();

		if($next.length>0)
		{
			$f.find(".next-photo").unbind().show().click(function(e){
				e.preventDefault();
	
				$next.trigger("click");
			})

			$f.find("#main").unbind().click(function(e){
				e.preventDefault();
	
				$next.trigger("click");
			})
		}
		else
			$f.find(".next-photo").hide();
			
		$f.css({
			left: ($(window).width()/2-$f.width()/2)+"px",
			top: ($(window).height()/2-$f.height()/2)+"px"
		});

		mainImagePos();
	})
	
	$(window).bind("resize scroll", mainImagePos)		

	//$(".full-gallery:last").trigger("click");

	$(".journal-show").click(function(e){
		e.preventDefault();
		$(".journal-show").hide();
		$(".journal-hide").show();
		$("#full").stop(true, true).animate({height:"844px"}, 800);				
	})
	
	$(".journal-hide").click(function(e){
		e.preventDefault();
		$(".journal-show").show();
		$(".journal-hide").hide();
		$("#full").stop(true, true).animate({height:"450px"}, 800);				
	})

	$(".video-show").click(function(e){
		e.preventDefault();
		$(".video-show").hide();
		$(".video-hide").show();
		$("#full-inside").stop(true, true).slideDown();
	})
	
	$(".video-hide").click(function(e){
		e.preventDefault();
		$(".video-show").show();
		$(".video-hide").hide();
		$("#full-inside").stop(true, true).slideUp();
	})
	
	$(".menu .name a").hover(function(){
		$(this).closest(".menu").toggleClass("menu-hover")
	})

	//rotator script
	var _pos=0;
	var _total=$(".rotator .journal-one").size()-parseInt($(".rotator").attr("rel"))+1;
	var one, w;

	$(".rotator .in").width(10000);

	$(".rotator .back").css({"visibility":"hidden"}).click(function(e){
		e.preventDefault();
		w=$(this).closest(".rotator");

		$(this).css({"visibility":"visible"});
		w.find(".next").css({"visibility":"visible"});

		_pos--;
		if(_pos>=0)
		{
			one=w.find(".journal-one").width();
			w.find(".visible .in").animate({"margin-left":-_pos*one})

			if(_pos-1<0)
				$(this).css({"visibility":"hidden"});
		}
	})

	$(".rotator .next").click(function(e){
		e.preventDefault();
		w=$(this).closest(".rotator");
		
		$(this).css({"visibility":"visible"});
		w.find(".back").css({"visibility":"visible"});

		_pos++;
		if(_pos<_total)
		{
			one=w.find(".journal-one").width();
			w.find(".visible .in").animate({"margin-left":-_pos*one})

			if(_pos+1==_total)
				$(this).css({"visibility":"hidden"});
		}
	})
})

function mainImagePos()
{
	if($("#full-image").is(":visible"))
	{
		$("#full-image").css({
			left: ($(window).width()/2-$("#full-image").width()/2)+"px",
			top: ($(window).scrollTop()+$(window).height()/2-$("#full-image").height()/2)+"px"
		})
	}
}

