var galleryImg = [];
var galleryThumb = [];
var galleryTextPos = [];
var galleryImgLink = [];
var galleryImgLinkTarget = [];
var galleryType = [];

var active_class;


$(document).ready(function() {
	getXML();
	
	$('.contentleft_home_btn').mouseenter(function(){
		$('.contentleft_home_btn_inner').stop(true, true).animate({
			left: '+=120'
		}, 250, 'swing');
	}).mouseleave(function(){
		$('.contentleft_home_btn_inner').stop(true, true).animate({
			left: '-=120'
		}, 250, 'swing');
	});
	

	$('.contentleft_home_bg').animate({
		left: '+=286'
	}, 400, function(){
		$('.contentleft_home_bc').animate({
			left: '+=286'
		}, 400, function() {
			$('.contentleft_home_btn').animate({
				left: '+=286'
			}, 400)
		});
	});
	
});


function getXML() {
	$.ajax({
        type: "GET",
		url: "setting1.xml",
		dataType: "xml",
		success: addContent
	});
	
}

function addContent(xml) {
	$(xml).find("data").each(function(){
		$(this).find("item").each(function(){
			galleryImg.push($(this).find("img").text());
			galleryThumb.push($(this).find("thumb").text());
			galleryTextPos.push($(this).find("textPosition").text());
			galleryImgLink.push($(this).find("imgLink").text());
			galleryImgLinkTarget.push($(this).find("imgLinkTarget").text());
			galleryType.push($(this).find("type").text());
		});
	});
	
	galleryImg.reverse();
	galleryThumb.reverse();
  	galleryTextPos.reverse();
  	galleryImgLink.reverse();
	galleryImgLinkTarget.reverse();
	galleryType.reverse();

	for(var i = 0; i < 5; i++){
		var child_html = "<div class='gallery_child'>";
		child_html += "<img class='gallery_child_img"
		if(i == 4){
		child_html += " active";
		}
		child_html += "' src='"+galleryThumb[i]+"' alt=''/>";
		child_html += "<div id='gallery"+i+"' class='black_overlay'";
		if(i == 4){
		child_html += " style='display:none;'";
		}
		child_html += "></div>";
		child_html += "</div>";
		$('#crh_gallery').append(child_html);
	}
	for(var i = 0; i < 5; i++){
		if(galleryType[i] != "swf"){
			var window_html = "<img id='gallery"+i+"' class='crh_child' style='display:none;' src='"+galleryImg[i]+"' alt='' />";
		} else {
			var window_html = "<OBJECT id='gallery"+i+"' class='flash_container crh_child' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' WIDTH='660' HEIGHT='315' id='4.swf' ALIGN=''><PARAM NAME=movie VALUE='images/home/files/.swf'> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#333399> <EMBED src='images/home/files/4.swf' quality=high bgcolor=#333399 WIDTH='660' HEIGHT='315' NAME='4' ALIGN='' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED> </OBJECT> ";
		}
			$('#crh_window').append(window_html);
	}
	$('.black_overlay').click(function() {
		$('.gallery_child_img').removeClass('active');
		$(this).parent().find('img').addClass('active');
		active_class = $(this).attr('id');
		$('#crh_window > .crh_child').css('display', 'none');
		$('#crh_window > #'+active_class).css('display', '');
		$('.black_overlay').css('display', '');
		$(this).css('display', 'none');
	});
	$('.black_overlay').mouseenter(function(){	
		$(this).stop(true, true).animate({
			opacity: .1}, 200);
	}).mouseleave(function() {	
		$(this).stop(true, true).animate({
			opacity: .8},200);
	});
		
}

	
