jQuery(function ($) {
	$('#UI_viewer').click(function (e) {

		$("#UI_footer").after('<div id="UI_media"><div class="top"></div><div class="middle"><h2>Le restaurant en images</h2><span class="close simplemodal-close">Fermer</span><div class="area"></div></div><div class="bottom"></div></div>');
            $("#UI_media .area").load("media.php", function(){
                $('#UI_media').modal({
				opacity:80,
				overlayClose:false,
				overlayCss: {backgroundColor:"#000", width:"800px", height:"550px"},
				onShow: function (dialog) {
				    var current = 0;
				    var max = $('#UI_media .viewer img').length;
					var pict_height = $('#UI_media .viewer').height();

					//$('#UI_viewer .list').width(pict_height*max);

				    $('#UI_media .prev').click(function(){
				        if(current == 0){
				            current = max-1;
						}else{
						    current--;
						}
						var newposition = (0-(pict_height*current))+'px';
						//console.log(current + ' > ' + newposition);
						$('#UI_media .list').stop().animate({top:newposition},450);
						$('#UI_media .viewer p').text((current+1) + '/' + max);
					});
				    $('#UI_media .next').click(function(){
				        if(current < (max-1)){
				            current++;
						}else{
						    current = 0;
						}
						var newposition = (0-pict_height*current)+'px';
						//console.log(current + ' > ' + newposition);
						$('#UI_media .list').stop().animate({top:newposition},450);
						$('#UI_media .viewer p').text((current+1) + '/' + max);
					});
					$('#UI_media .viewer p').text((current+1) + '/' + max);
					$('#UI_media .close').click(function(){
						//$('#UI_media').modal.close();
					});

				},
				onClose: function (dialog) {
				     $.modal.close();//$.modal.close();
				     $('#UI_media').remove();
				}
			});
	    });
		return false;
	});
});
function addWindow(title){
    if($("#UI_window").length > 0){
        $("#UI_window").remove();
    }
    $("#UI_footer").after('<div id="UI_window"><div class="window"><div class="top"></div><div class="middle"><h2>'+title+'</h2><span class="close"><a href="javascript:removeWindow()">Fermer</a></span><div class="area"></div></div><div class="bottom"></div></div></div>');
    $("#UI_window .window").hide();

}
function removeWindow(){
    $("#UI_window").remove();
}
function setWindow(){
	var newX = $(window).width()/2 - $("#UI_window .window").width()/2;
	var newY = $(window).height()/2 - $("#UI_window .window").height()/2;
	$("#UI_window .window").css({left: newX, top: newY});
	$("#UI_window").width($(document).width());
	$("#UI_window").height($(document).height());
	$("#UI_window .window").fadeIn(500)
}
/*              MEDIA                 */
function addViewer(title){
    if($("#UI_media").length > 0){
        $("#UI_media").remove();
    }
    /*
    $("#UI_footer").after('<div id="UI_media"><div class="media"><div class="top"></div><div class="middle"><h2>'+title+'</h2><span class="close"><a href="javascript:removeViewer()">Fermer</a></span><div class="area"></div></div><div class="bottom"></div></div></div>');
    //$("#UI_media .media").hide();

    */

}
function removeViewer(){
    $("#UI_media").remove();
}
function setViewer(){
	var newX = $(window).width()/2 - $("#UI_media .media").width()/2;
	var newY = $(window).height()/2 - $("#UI_media .media").height()/2;
	$("#UI_media .media").css({left: newX, top: newY});
	$("#UI_media").width($(document).width());
	$("#UI_media").height($(document).height());

	$("#UI_media .media").fadeIn(500);

	$('#UI_media .handle').hover(function(){
	    $(this).addClass("hover");
	}, function(){
	    $(this).removeClass("hover");
	});

}

function partners(url){
    addWindow("Nos partenaires");

    $("#UI_window .area").load(url, function(){
        setWindow();
    });
}
function mentions(url){
    addWindow("Mentions légales");

    $("#UI_window .area").load(url, function(){
        setWindow();
    });
}
function credits(url){
    addWindow("Crédits");
    $("#UI_window .area").load(url, function(){
        setWindow();
    });
}

function gotoPage(id){
	$('#UI_nav li').removeClass('current');
	$('#UI_nav li').eq(id).addClass('current');
	$('#UI_content div.panel').hide();
	$('#UI_content div.panel').eq(id).fadeIn('slow');
	if(id == 0){
	    $("#UI_mea").slideUp(300);
	}else{
	    $("#UI_mea").slideDown(300);
	}
}

$(document).ready(function(){
	$('#UI_content div.panel:gt(0)').hide();

    $("#UI_mea").hide();
	$('#UI_nav  li').click(function(){
		$('#UI_nav  li').removeClass('current');
		$(this).addClass('current');

		var n = $(this).parent().children("li").index(this);
		/*
		$('#UI_content div.panel').fadeOut('fast', function(){
			$('#UI_content div.panel').eq(n).fadeIn('slow');
		});
		*/
		$('#UI_content div.panel').hide();
		$('#UI_content div.panel').eq(n).fadeIn('slow');
		if(n == 0){
		    $("#UI_mea").slideUp(300);
		}else{
		    $("#UI_mea").slideDown(300);
		}
	});
	$('#UI_vin, #UI_carte, #UI_viewer').hover(function(){
	    $(this).addClass("hover");
	}, function(){
	    $(this).removeClass("hover");
	});
});

// Données Google Analytics
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

try {
var pageTracker = _gat._getTracker("UA-257638-21");
pageTracker._trackPageview();
} catch(err) {}
/*
*/

