// JavaScript Document
var roTime;
var roNum=-1;
var tmp='';
var myId;
$(document).ready(function(){
	//RoAjax();
	
	$('#main_3').find('a').mouseover(function(){$(this).css('background-position','0 -11px');});
	$('#main_3').find('a').mouseout(function(){
		
		if($(this).attr('class')!='sel'){
			$(this).css('background-position','0 0');
		}
	});
					
	$('#main_3').find('a').click(function(event){
		if (event.target == this) {
			$('#main_4').hide();
			$(this).parent().find('a').css('background-position','0 0');
			$(this).parent().find('a').removeClass('sel');
			$('#main_4').html(lev0[$(this).attr('value')]);
			tmp=lev1[$(this).attr('value')];
			$('#main_4').fadeIn('slow');
			$(this).css('background-position','0 -11px');
			$(this).addClass('sel');
			
			 
			
			$('#main_4').find('a').click(function(event){
				if (event.target == this) {
					barClick($(this).attr('value'));
				}
			})
		}
	})
	$('#footer').find('a').find('img.o').mouseover(function(event){
			if (event.target == this) {
				$(this).hide();
				$(this).parent().find('.i').show()
			}
											  
	});
	$('#footer').find('a').find('img.i').mouseout(function(event){
			if (event.target == this) {
				$(this).hide();
				$(this).parent().find('.o').show()
			}
											  
	});
	
})



function barMouseOver(e,xml){
	var q=$(xml).find('lev').eq(e).find('info2');
	var str='';
	for(var i=0;i<q.length;i++){
		str+='<a href="#" style="background-image:url(/test/'+q.eq(i).find('img').text()+')" value="'+i+'"></a>';
	}
	$('#main_4').html(str);
	$('#main_4').find('a').click(function(event){
		if (event.target == this) {
			barClick(e,$(this).attr('value'),xml);
		}
	})
}


function barClick(id){

	var str='<div id="showImg" ></div>';
	str+='<div id="mTitle">'+info[id]+'</div>';
	str+='<div id="leftBar"><div id="barMain"></div><div id="btn"></div></div>';
	str+='<div id="mBrief">'+brief[id]+'</div><div id="mLists"><table border="0" cellspacing="7" cellpadding="0"><tr>';
	if(img[id].length){
		for(var i=0;i<img[id].length;i++){
		str+='<td><img src="/projects/images/small/'+img[id][i]+'_1.jpg"  value="/projects/images/medium/'+img[id][i]+'_0.jpg" '+imgsize[id][i]+ ' /></td>';
		}
	}
	str+='</table></div><a href="#" id="close">CLOSE</a>';
	$('#map').html(str);
	//if($.browser.msie && $.browser.version=='6.0')
		//$('#leftBar').css({'left': '-228px'});
	$('#barMain').html(tmp);
	/*$('#barMain').find('a').each(function(){
		if($(this).attr('value')==id)
			$(this).hide();
		else
			$(this).show();
	});*/
	$('#map').show('slow');
	$('#map').parent().prepend('<div id="nous"></div>');
	$('#nous').show('fast');
	$('#nous').animate({right:'0px'},'slow');
	
	$('#close').click(function(){
		$('#map').hide('slow');		
		window.clearInterval(roTime);
		$('#nous').remove();
	});
	
	$('#mBrief').animate({left:'28px'},3000);
	$('#mLists').fadeIn(3000); 

	
	roTime=window.setInterval(tip,3000);
	imgc();
	btn();
	
	
	
	$('#barMain').find('a').click(function(){
		move($(this).attr('value'));							   
	});
	
}

function gotoimg(){
	roTime=window.setInterval(tip,3000);
}

function tip(){
	var img=$('#mLists').find('img');
	if(img.length>0){	
		
		var n=img.length-1;
		if(roNum<n) roNum++;
		else roNum=0;
		var i="url("+img.eq(roNum).attr('value')+")";
		$('#showImg').css("background-image",i);
		$("#showImg").fadeIn(700); 
		$('#mLists').find('td').css({'border':'1px solid #6d6d6d'}); 
		img.eq(roNum).parent().css({'border':'1px solid #f7941d'}); 
		//window.setTimeout(tip2,2300);
		
	}
	if(img.length==1){
		clearTimeout(roTime);
	}
}


function tip2(){
	$("#showImg").fadeOut(700); 
}

function move(id){
	window.clearInterval(roTime);
	$('#showImg').fadeOut(700);
	$('#mLists').fadeOut(700);
	$('#mTitle').fadeOut(700);
	$('#mBrief').animate({'left': '-390px'}, 700);
	//if($.browser.msie && $.browser.version=='6.0')
		$('#leftBar').animate({'left': '-228px'}, 700);
	//else
		//$('#leftBar').animate({'left': '-218px'}, 700);
	$('#btn').css('background-position','0 0');
	$('#barMain')
	myId=id;
	window.setTimeout(moveId,700);
	
}

function moveId(){
	
	var str='<table border="0" cellspacing="7" cellpadding="0"><tr>';
	if(img[myId].length){
		for(var i=0;i<img[myId].length;i++){
		str+='<td><img src="/projects/images/small/'+img[myId][i]+'_1.jpg"  value="/projects/images/medium/'+img[myId][i]+'_0.jpg" '+imgsize[myId][i]+ ' /></td>';
		}
	}
	/*$('#barMain').find('a').each(function(){
		if($(this).attr('value')==myId)
			$(this).hide();
		else
			$(this).show();
	});*/
	
	str+='</table>';
	$('#mTitle').html(info[myId]);
	$('#mBrief').html(brief[myId]);
	$('#mLists').html(str);
	roNum=0;
	var i="url("+$('#mLists').find('img:eq(0)').attr('value')+")";
	$('#mLists').find('img:eq(0)').parent().css({'border':'1px solid #f7941d'}); 
	$('#showImg').css({"background-image":i});
	//window.setInterval(tip,3000);
	$('#showImg').fadeOut(700);
	$('#mLists').fadeIn(700);
	$('#mTitle').fadeIn(700);
	$('#mBrief').animate({'left': '28px'},700);
	$('#showImg').fadeIn(700);
	//$('#leftBar').animate({'left': '0px'}, 700);
	$('#btn').css('background-position','0 0');
	imgc();
}


function imgc(){
	$('#mLists').find('img').click(function(event){
		if (event.target == this) {
			
			window.clearInterval(roTime);
			var n=$('#mLists').find('img').index(this);
			roNum=n;
			$('#mLists').find('td').css({'border':'1px solid #6d6d6d'}); 
			var i="url("+$(this).attr('value')+")";
			$(this).parent().css({'border':'1px solid #f7941d'}); 
			$('#showImg').css({"background-image":i});
			$('#showImg').show();
			window.setTimeout(gotoimg,300);
		}
	});
	
	}
	
function btn(){
		$('#btn').click(function(event){
		
		if (event.target == this) {
			if($(this).parent().css('left')=='0px'){
				//if($.browser.msie && $.browser.version=='6.0'){
					$('#leftBar').animate({'left': '-228px'},"slow");
				//}else{
				//	$('#leftBar').animate({'left': '-218px'},"slow");
				//$('#leftBar').animate({'left': '-218px'}, "slow");
				//}
				$(this).css('background-position','0 0');
			}else{
				$('#leftBar').animate({'left': '0px'}, "slow");
				$(this).css('background-position','0 -45px');
			}
		}
	})
}