(function (jQuery){
	jQuery(function (){
		jQuery(document).ready(function (){
			var maxcnt = jQuery('div.galleryLeft div.thmnailImgArea ol li a').length;
			jQuery("div.galleryRight div.thmnailImgArea").carousel({dispItems: 3});
			jQuery('div.galleryLeft div.thmnailImgArea ol li a').eq(0).css("opacity", "0.5");
			var cacheImage = document.createElement('img');
			for( var i = 0; i<jQuery('div.galleryLeft div.thmnailImgArea ol li a').length; i++){
				cacheImage.src = jQuery('div.galleryLeft div.thmnailImgArea ol li a').eq(i).attr("href");
			}
			jQuery('div.galleryLeft div.thmnailImgArea ol li a').click(function (){
				jQuery('div.galleryLeft div.thmnailImgArea ol li a').css("opacity", "1");
				jQuery('div.galleryLeft div.galleryImgArea img').attr("src", jQuery(this).attr("href"));
				selected = jQuery(this).index();
				jQuery(this).css("opacity", "0.5");
				return false;
			});
			jQuery('div.galleryRight div.pageWrap ul.page li a').click(function (){
				jQuery('div.galleryRight div.thmnailImgArea ul li a').css("opacity", "1");
				jQuery('div.galleryRight div.galleryImgArea iframe').attr("src", jQuery(this).attr("href"));
				jQuery(this).css("opacity", "0.5");
				return false;
			});
			setInterval(function(){
				for( i=0; i<jQuery('div.galleryLeft div.thmnailImgArea ol li a').length; i++){
					if(jQuery('div.galleryLeft div.thmnailImgArea ol li a').eq(i).css("opacity") == 0.5){
						if( i == (jQuery('div.galleryLeft div.thmnailImgArea ol li a').length-1)){
							jQuery('div.galleryLeft div.thmnailImgArea ol li a').eq(0).click();
							jQuery('div.galleryLeft div.thmnailImgArea ol').animate({"marginLeft": "0"}, "fast");
						} else {
							jQuery('div.galleryLeft div.thmnailImgArea ol li a').eq(i+1).click();
							if( ((i+1) % 5) == 0){
								jQuery('div.galleryLeft div.thmnailImgArea ol').animate({"marginLeft": "-=550px"}, "slow");
							}
						}
						break;
					}
				}
			}, 10000);
		});
	})
})(jQuery);

