// Initialization
var text_settings = new Array();
var num=0;
$.naviText = {
	init: function() {
		for (module in $.naviText) {
			if ($.naviText[module].init)
				$.naviText[module].init();
		}
	}
};

$(document).ready($.naviText.init);

$.naviText.fn = {
	init: function() {
		$('a.naviText')
			.bind('click', this.click)
			.bind('mouseover', this.enter)
			.bind('mouseout', this.exit)
			.each(this.preload);
	},
	preload: function(fn) {
		var vp=($(this).parent().attr('class').match(/play_video/))?true:false;
		this.color = $(this).css('color');
		$(this).css({color:'#fff', visibility:'visible'});
		$(this).delay(1000).animate({color:"#999999"},1000);
		this.lock=false;
		this.id=num;
		text_settings.push(this);
		if($(this).parent().attr('class').match(/first/)){
			var l=this.href.substring(0,this.href.length-1)+'.html';
			var obj=this;
			$('#photo').css({opacity:0});
			$('#photo').css({visibility:'hidden'});
			$('#photo').load(l,function(text,status){
				$(this).append(l);
				var target = this;
				if(text.match(/wrap/)){
					if($(target).find("img")){
						var img = new Image();
						$(img).load( function(){
							if($(this).attr("width")<$(this).attr("height")){
								$(target).css({top:'30px'});
								$(target).find('h2').css({color:'#fff',visibility:'visible'});
								$(target).find('h2').delay(2000).animate({color:'#999999'},1000);
							}else{
								$(target).css({top:'96px'})
								$(target).find('h2').css({visibility:'hidden'});
							}
							$(target).css({visibility:'visible'});
							$(target).width($(this).attr("width")).height($(this).attr("height")).delay(0).animate({opacity:1},1000);
						}).error(function () {
						}).attr('src', $(target).find("img").attr("src"));
					}
					$(obj).animate({color:'#b3b3b3'},1000);
				}
			});
		}
		num++;
	},
	click: function() {
		this.lock=true;
	},
	enter: function() {
		if(this.lock) return;
		$('#photo').css({opacity:0,visibility:'hidden'});
		var vp=($(this).parent().attr('class').match(/play_video/))?true:false;
		var l=this.href.substring(0,this.href.length-1)+'.html';
		var obj=this;
		$('#photo').load(l,function(text,status){
			$(this).append(l);
			var target = this;
			if(text.match(/wrap/)){
				if($(target).find("img")){
					var img = new Image();
					$(img).load( function(){
						if($(this).attr("width")<$(this).attr("height")){
							$(target).css({top:'30px'})
							$(target).find('h2').css({color:'#fff',visibility:'visible'});
							$(target).find('h2').delay(1000).animate({color:'#999999'},1000);
						}else{
							$(target).css({top:'96px'})
							$(target).find('h2').css({visibility:'hidden'});
						}
						$(target).stop(true,true);
						$(target).css({opacity:0});
						$(target).css({visibility:'visible'});
						$(target).width($(this).attr("width")).height($(this).attr("height")).animate({opacity:1},1000);
						$(target).fadeIn(1000);
					}).error(function () {
					}).attr('src', $(target).find("img").attr("src"));
				}

				$(obj).stop(true,true);
				$(obj).animate({color:'#b3b3b3'},1000);
				for(var i=0;i<text_settings.length;i++){
					if(text_settings[i].id!=obj.id){
						$(text_settings[i]).stop(true,true);
						$(text_settings[i]).animate({color:'#999999'},1000);
					}
				}
			}
		});
	},
	exit: function() {
	}
};

//EOF
