// function of JennyJenny


$(document).ready(function(){
	//***************************************** check browser set shadow *****************************************
	if ($.browser.msie) {
		$('.shadow').css({top:'-8px',left:'-8px'});
	}
	var userAgent = navigator.userAgent.toLowerCase();
	$.browser.chrome = /webkit/.test(navigator.userAgent.toLowerCase());
	
	//***************************************** project show hide *****************************************
	
	var total = $('.project-block').length;
	
	for(var i=1;i<total;i++){
		$('.project-block .content').eq(i).addClass('nodisplay');
		$('.project-block .headline').eq(i).addClass('offheadline');
		$('.project-block .headline>img').eq(i).attr('src','images/project_down_arrow.jpg');
	}
	
	$('.project-block .headline').click(function(event){
		var target = $(event.target);
		if(!target.is('span')){
			var content = $(this).next();
			var isHidden = content.is(':hidden');
			if(isHidden){
				content.show('blind');
				$(this).removeClass('offheadline');
				$('>img', this).attr('src','images/project_up_arrow.jpg');
			}else{
				content.hide('blind');
				$(this).addClass('offheadline');
				$('>img', this).attr('src','images/project_down_arrow.jpg');
			}
		}
	});
	
	
	//***************************************** movie and book hide *****************************************
	$('#book').hide();
	
	$('#movies-btn').click(function(){
		$('#books-btn').removeClass('on');
		$(this).addClass('on');
		$('#movies').fadeIn();
		$('#book').hide();
		return false;
	});
	
	$('#books-btn').click(function(){
		$('#movies-btn').removeClass('on');
		$(this).addClass('on');
		$('#book').fadeIn();
		$('#movies').hide();
		return false;
	});
	
	//***************************************** gallery load photo *****************************************
	var photoNum = 0
	
	$('.left-arrow').hover(function(){
		$(this).css({'background-position':'left'});
	},function(){
		$(this).css({'background-position':'-70px'});	
	});
	
	$('.right-arrow').hover(function(){
		$(this).css({'background-position':'right'});
	},function(){
		$(this).css({'background-position':'-70px'});	
	});
	
	$('.left-arrow').click(function(){
		photoNum--;
		if(photoNum < 0){
			photoNum =  $('.gallery>a').children().length-1;
		}
		var thumb = $('.gallery>a').eq(photoNum);
		$('.gallery-photo').addClass('loading').show();
		$('.gallery-photo>img').fadeOut(1000,function(){
			$('.gallery-photo>img').attr('src', thumb.attr('href'));
			$(this).fadeIn(1000);
			$('.gallery-photo').removeClass('loading');
		});
		
	/*	$('.gallery-photo').empty().addClass('loading').show();
		var img = new Image();
		$(img).load(function() {
			$(this).hide();
			$('.gallery-photo').removeClass('loading').append(this).append('<div class="left-arrow"></div>');
			$(this).fadeIn();
		})
		.error(function() {
			//alert('error');
		})
		.attr('src', thumb.attr('href')); */
		
		//$('.gallery-photo>img').attr('src', thumb.attr('href'));
		
		return false;
	});
	
	$('.right-arrow').click(function(){
		photoNum++;
		if(photoNum > $('.gallery>a').children().length-1){
			photoNum = 0;
		}
		var thumb = $('.gallery>a').eq(photoNum);
		
		$('.gallery-photo').addClass('loading').show();
		$('.gallery-photo>img').fadeOut(1000,function(){
			$('.gallery-photo>img').attr('src', thumb.attr('href'));
			$(this).fadeIn(1000);
			$('.gallery-photo').removeClass('loading');
		});
		/*$('.gallery-photo>img').remove();
		$('.gallery-photo').addClass('loading').show();
		var img = new Image();
		$(img).load(function() {
			//$(this).hide();
			$('.gallery-photo').removeClass('loading').append(this);
			$(this).fadeIn();
		})
		.error(function() {
			//alert('error');
		})
		.attr('src', thumb.attr('href'));*/
		//$('.gallery-photo>img').attr('src', thumb.attr('href'));
		
		return false;
	});
	
	$(".gallery>a").click(function(){
		var thumb = $(this);
		photoNum = $('.gallery>a').index(this);
		
		$('.gallery-photo').addClass('loading').show();
		$('.gallery-photo>img').fadeOut(1000,function(){
			$('.gallery-photo>img').attr('src', thumb.attr('href'));
			$(this).fadeIn(1000);
			$('.gallery-photo').removeClass('loading');
		});
		/*$('.gallery-photo').empty().addClass('loading').show();
		var img = new Image();
		$(img).load(function() {
			$(this).hide();
			$('.gallery-photo').removeClass('loading').append(this);
			$(this).fadeIn();
		})
		.error(function() {
			//alert('error');
		})
		.attr('src', thumb.attr('href')); */
		//$('.gallery-photo>img').attr('src', thumb.attr('href'));
		
		return false;
	});
	
});

function changeMovie(path){
	var swf = swfName('video_player');
	var swf2 = swfName('flash_content');
	swf.changeMovie(path);
	swf2.playMovie();
	return false;
}

function swfName(str) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[str];
	}else {
		return document[str];
	}
}

function setFlashHeight(divid, newH, stateVal){
	document.getElementById(divid).style.height = newH;
}

function closeSound(){
	var swf2 = swfName('flash_content');
	swf2.playMovie();
}
