$(document).ready(function(){
	
	showDes();
	centerPopup();
	disablePopup();
	readStory();
	image_left();
	image_right();
});

function image_left(){
	$('#go_image_left').click(function(){
		var total = parseInt($('#total_nums').text());
		var c_id = parseInt($('#current_image_id').text());
		//alert(c_id);
		if(c_id > 1) {
			c_id--;
			
			var contents = $('.left_right_'+c_id).html();
			//alert(contents);
			if(contents) {
				$('#gallery_right_wrap').html(contents);
				$('#current_image_id').html(c_id);
			}			
		}
		//alert(total);alert(c_id);		
	});
}
function image_right(){
	$('#go_image_right').click(function(){
		var total = parseInt($('#total_nums').text());
		var c_id = parseInt($('#current_image_id').text());
		//alert(c_id);
		if(c_id < total) {
			c_id++;
			
			var contents = $('.left_right_'+c_id).html();
			//alert(contents);
			if(contents) {
				$('#gallery_right_wrap').html(contents);
				$('#current_image_id').html(c_id);
			}			
		}
		//alert(total);alert(c_id);

	});
}

function readStory() {
	$('#read_story').click(function(){
		$("#popup_des").fadeIn("slow");
		$('#pupup_txt').show();		
	})
}
function showDes() {
	$('.gallery_small_img').click(function(){		
		var content = $(this).next().html();
		var n_id = $(this).next().attr("class");
		
		var really_id = n_id.substring(11);
		//alert(really_id);
		$('#current_image_id').html(really_id);

		if(content) {
			$('#gallery_right_wrap').html(content);
			//$("#popup_des").fadeIn("slow");
			//alert(des);			
		}

	});
	
}
function disablePopup(){
	$('#pupup_colse').click(function(){
		$('#popup_des').fadeOut("slow");
	})
}

function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popup_des").height();
	var popupWidth = $("#popup_des").width();
	//centering
	$("#popup_des").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
}


function init_dw_Scroll() {
    var wndo = new dw_scrollObj('wn', 'lyr1');
    wndo.setUpScrollControls('scrollLinks');
}

// if code supported, link in the style sheet and call the init function onload
if ( dw_scrollObj.isSupported() ) {
    //dw_writeStyleSheet('css/scroll.css');
    dw_Event.add( window, 'load', init_dw_Scroll);
}
