 /*
 * personalize.js (mitsubishi personalize js)
 *  @require jquery 1.2.6 -
 *  Copyright Mitsubishi Corporation. All rights reserved.
 */

DIA.personalize = {
	flag: true, //personalize flag
	suffix: '_on', //navi img suffix on/off
	swhtml: 'switch.html?width=864',
	initc: function(){
		$("#content_swf").hide();
		tb_show('switch', DIA.personalize.swhtml);
	},
	change: function(key, timing){
		var url = 'index_'+key+'.html';
		
		if(key == 'normal'){
			url = 'index.html';
		}
		
		if(DIA.personalize.flag){
			DIA.personalize.flag = false;
			if(!timing){
				tb_remove();
				$('#loading p.catch').hide()
					.parent()
					.find('p.catch').show()
					.end()
					.show();
			}
				
			$.ajax({
				url: url,
				method: 'get',
				success: function(data){
					$('#load_content').html($('#load_content', data).html());
					$('#side .link_switch').show();
					DIA.personalize.setpage(key);
					if(timing){
						$('#loading').hide();
					}else{
						$.cookie('ck', key, { expires: 90 });
						$('#loading').fadeOut(1500);
						$("#content_swf").show();
					}
					DIA.personalize.flag = true;
					DIA.initfontswitch();
				},
				error: function(){
					DIA.personalize.flag = true;
					DIA.initfontswitch();
				}
			});
		}
		
		return false;
	},
	setpage: function(current){
		$('body').removeAttr('class');
		$('body').addClass(current);
		window.scrollTo(0,0);
		var defaultValue = $('#top .search_box input.txtarea').val();
		$('#top .search_box input.txtarea').addClass('default')
		.focus(function(){
			if($(this).val() == defaultValue){
				$(this).val('').removeClass('default');
			}
		})
		.blur(function(){
			if($(this).val() == defaultValue | $(this).val() == ''){
				$(this).val(defaultValue).addClass('default');
			};
		});
		$('#top .search_box input.btn_search').click(function(){
			if($('#top .search_box input.txtarea').val() == defaultValue){
				$('#top .search_box input.txtarea').val('');
			};
		});
		$('.load_json').show();
		
	}
};

$(function(){
	//show personalize button
	$('#side .link_switch').show();
	
	$('p#switch').css('display','inline');
	var cur_ck = $.cookie('ck');
	if(cur_ck != null && cur_ck != 'normal'){
		DIA.personalize.change(cur_ck, true);
	}else{
		$('.load_json').show();
		$("#content_swf").show();
	}
});

