/* menu */
jQuery.menu = function(id){
    $(id).find('ul').find('li').hover(function(){

        clearTimeout($(this).data('jQueryMenu'));
        $(this).find('ul:first').animate({
            height:'show'
        }, 'normal');
    },

    function(){
        var mm = $(this);
        var timer = setTimeout(function(){
            mm.find('ul:first').animate({
                height:'hide',
                opacity:'hide'
            }, 'slow');
        }, 0);
        $(this).data('jQueryMenu', timer);

    });

}
$.menu("#nav");

var div= $('.detail-nav');
div.css("top", ($(window).height())/2-55 + 'px');

var div= $('#detail-next');
div.css("left", ($(window).width())-55  + 'px');

/*var div= $('.detail-share');
div.css("top", ($(window).height())-133 + 'px');*/

/* slide */
$('#imgbg').cycle({
    fx:    'fade',
    speed:  3000
});
	
$("#photolist").easySlider({
    auto: true,
    pause: 7000,
    speed: 2000,
    nextId: "slider1next",
    prevId: "slider1prev"
});
	
$("#weddinglist").easySlider({
    auto: true,
    pause: 7000,
    speed: 2000,
    nextId: "slider1next",
    prevId: "slider1prev"
});
	
/* content */
$(function(){
    $('.scroll-pane').jScrollPane();
});
    
var div= $('#slidertbl');
div.css("height", ($(window).height())-200  + 'px');
	
var div= $('.text');
	div.css("height", ($(window).height())-111  + 'px');
	div.css("margin", ($(window).height())/15  + 'px');
			
$("#content").fadeIn(500);
	
$("#nav a, .slider a, .detail-nav a, .close a").click(function(event){
    $("#content").fadeOut(500);
});

/* image,div resizer */
function imaginarium2(){
	var winW = $(window).width();
	var winH = $(window).height()-50;

	$('#imgbg').width(winW);

	$('#imgbg img').each(function(index) {
		var newW = 0;
		var newH = 0;

		var oriW = $(this).width();
		var oriH = $(this).height();

		if( winH > oriH) {
			var difHRatio = winH / oriH;
			var newH = winH;
			var newW = Math.round(difHRatio*oriW);
			if(winW > newW) {
				var difWRatio = winW / newW;
				var newW = Math.round(difWRatio*newW);
				var newH = Math.round(difWRatio*newH);
			}
		} else {
			var difHRatio = winH / oriH;
			var newH = Math.round(difHRatio*oriH);
			var newW = Math.round(difHRatio*oriW);
			if(winW > newW) {
				var difWRatio = winW / newW;
				var newW = Math.round(difWRatio*newW);
				var newH = Math.round(difWRatio*newH);
			}
		}
		$(this).width(newW);
		$(this).height(newH);
	});
}

function frontHi(){
	var winW = $(window).width();
	var winH = $(window).height();

	posL = (winW-300)/2;
	posT = (winH-150)/2;

}


$(document).ready(function(){
	frontHi();
	imaginarium2();
	$('#WDate').datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: 'yy-mm-dd',
		yearRange: '2011:2020'
	});

	$('#frontclose').click(function(){
		$('#welcome').css("display", "none");
	});

	$('#twit-close').click(function(){
		$('#twitter').css("display", "none");
	});
});

$(window).resize(function() {
	imaginarium2();
	var div= $('#detail-next');
	div.css("left", ($(window).width())-55  + 'px');
});


