/*
 * plugin:jquery.expandContents.js
 * version:1.0(2011.11.27)
 * requires:jQuery v1.4.2 later
 * author:Manabu Kushimoto(http://web-park.org)
 */

jQuery(function($){

var $overlay=$('<div id="expand_overlay" />');
var $alt=$('<p id="alt_txt" />');
var window_h=$("html").height();
var active="active";

$overlay.appendTo($("div#top_warp2")).hide();
$overlay.css({height:window_h+"px",opacity:0.8});
$("div#title_bar").append($alt)
$alt.text($("ul#thumb_list li:eq(0)").find("img").attr("alt"));
$("ul#l_img li").not($("ul#l_img li:eq(0)")).hide();
$("ul#l_img li:eq(0)").addClass(active)

$.fn.expandContents=function(options){

var op=$.extend($.fn.expandContents.defaults,options);
var $t=$(this);

function expand(){
clearInterval(intervalEvent);
$overlay.stop(true,true).fadeIn(op.speed);
$t.stop(true,false).animate({
width:op.ex_w+"px",
height:op.ex_h+"px"
},op.speed,"swing");
op.$btm.animate({
bottom: 0
},op.speed*2,"swing");
$("div#main_body").css("z-index",200);
};

function reduction(){
$overlay.stop(true,true).fadeOut(op.speed);
op.$btm.stop(true,false).animate({
bottom: "-"+op.btm_h+"px"
},op.speed,"swing",function(){
$t.stop(false,false).animate({
width:op.st_w+"px",
height:op.st_h+"px"
},op.speed,"swing");
$("div#main_body").css("z-index",2);
});
autoChange();
};

op.$thumb.find("li").each(function(){
$(this).find("a").click(function(){
var $id=$($(this).attr("href"));
var $img=$(this).find("img");
var img={
alt:$img.attr("alt")
}
$alt.text(img.alt);
op.$large.find("li").not($id).fadeOut(600);
$("ul#l_img li."+active).removeClass(active);
$id.fadeIn(600).addClass(active);
return false;
});
});

function autoChange(){
intervalEvent=setInterval(function(){
var active_index=$("ul#l_img li").index($("ul#l_img li."+active));
var len=$("ul#l_img li").length;
if(active_index==(len-1)){
$("ul#l_img li").eq(active_index).fadeOut(600,function(){
$(this).removeClass(active);
$("ul#l_img li:eq(0)").fadeIn(600).addClass(active);
$alt.text($("ul#l_img li:eq(0) img").attr("alt"));
});
}else{
$("ul#l_img li").eq(active_index).fadeOut(600,function(){
$(this).removeClass(active);
$(this).next("li").fadeIn(600).addClass(active);
$alt.text($(this).next("li").find("img").attr("alt"));
});
}
},5000);
};
autoChange();

$t.hover(function(){ expand(); },function(){ reduction(); });
$overlay.click(function(){ clearInterval(intervalEvent); reduction(); return false; });

};

$.fn.expandContents.defaults={
st_w:930,
st_h:340,
ex_w:950,
ex_h:485,
$btm:$("div#info_area"),
btm_h:60,
speed:300,
$thumb:$("ul#thumb_list"),
$large:$("ul#l_img")
}

$("div#expand_contents").expandContents()

});
