var crsl_data = [];
var crsl_min = {'0': 'c_crsl1', '1': 'c_crsl2', '2': 'c_crsl3'};


function setCrslData(id)
{
	return crsl_data[id];
}


function crslReinit(id)
{
	var carouselObj = document.getElementById('carousel');
	
	carouselObj.reinit(id);
}


function crslHide()
{
	var carouselObj = document.getElementById('carousel');
	//var carouselObj = isInternetExplorer ? document.all.carousel : document.carousel;

	carouselObj.hideAll();
	
	//alert(carouselObj);
}


function crslSwitch(o)
{
	crslHide();
	//$('#c_crsl1 OBJECT').hide();
	var top_obj = $('#c_crsl1 .cm');
	top_obj.show();
	
	var bottom_obj = $(o).parents('.cm'); //$('#c_crsl' + id + ' .cm');
	var bottom_cnt = bottom_obj.parents('.cm-container'); 
	
	var id = bottom_obj.attr('crsl_id');
	bottom_obj.width(bottom_obj.width());
	
	var top_ofs = top_obj.offset();		
	var bottom_ofs = bottom_obj.offset();
	//console.log(id);
	//console.log(bottom_ofs);
	
	top_obj.appendTo('BODY').css({top: top_ofs.top, left: top_ofs.left});
	top_obj.animate({left: bottom_ofs.left, top: bottom_ofs.top}, 300, 'swing', function() {
			top_obj.css({left: 0, top: 0, width: bottom_cnt.width()});
			top_obj.appendTo(bottom_cnt);
		});

	bottom_obj.appendTo('BODY').css({top: bottom_ofs.top, left: bottom_ofs.left});
	bottom_obj.animate({left: top_ofs.left, top: top_ofs.top}, 300, 'swing', function() {
			bottom_obj.css({left: ($('#c_crsl1').width() - 650) / 2, top: 0, width: '650px'});
			//bottom_obj.css({width: '650px', position: 'absolute'});
			bottom_obj.appendTo($('#c_crsl1')).hide();

			crslReinit(id - 1);
		});

}


$(document).ready(function() {
		for(i in crsl_min) {
			var crsl = $('#' + crsl_min[i]);
			crsl.append('<div class="cm" crsl_id="' + (parseInt(i) + 1) + '" style="top: 0px; left: 0px;"><div class="cm-left" style="background: #' + crsl_data[i].bgcolor.toString(16) + ';"></div><div class="cm-right"></div></div>');
			
			var cm_left = crsl.find('.cm-left');
			cm_left.corner('tl tr #CDC1AC 10px').corner('bl br #C0AF94 10px');
			cm_left.append('<div class="cm-left-inner"><a href="javascript://" style="color: #' + crsl_data[i].name_color.toString(16) + ';" onclick="crslSwitch(this);">' + crsl_data[i].crsl_name + '</a></div>');
			
			var cm_left_inner = cm_left.find('.cm-left-inner');
			cm_left_inner.css('top', (cm_left.height() - cm_left_inner.height()) / 2);
			
			var cm_right = crsl.find('.cm-right');
			cm_right.corner('tl tr #CDC1AC 10px').corner('bl br #C0AF94 10px');
			//cm_right.
			//console.log(crsl);
			var _text = '';
			for(var j = 0; j < crsl_data[i].page_data.length; j++) {
				if(crsl_data[i].page_data[j].top == true)
					_text = crsl_data[i].page_data[j].html;
			}
			
			cm_right.append(_text);
			
			var cm = crsl.find('.cm');
			cm.width(cm.width());
		}
		
		$('#c_crsl1 .cm').width(650);
		$('#c_crsl1 .cm').css({left: ($('#c_crsl1').width() - 650) / 2});
		$('#c_crsl1 .cm').css('display', 'none');
		
	});

