jQuery(function(){
    //enable_logging();
    enable_lightbox();
    enable_facebox();

    jQuery('ul.home-menu').superfish();
    jQuery('ul.inside-menu').superfish();
    log('menus enabled');
});// end document ready


function enable_lightbox(){
    //image links with jlightbox class
	jQuery("a.jlightbox").lightbox();
	jQuery("a.lightbox").lightbox();

/*
    jQuery.each(jQuery(".edited_content a[href$='.jpg']"), function(i, item) {
        if (!$(item).attr('title'))
            $(item).attr('title', $(item).text());

        log('link: '+ i + ' - '+ $(item).attr('title'));
    });
*/

    //image links on pages
    jQuery(".edited_content a[href$='.jpg']").lightbox();
    jQuery(".edited_content a[href$='.jpeg']").lightbox();
    jQuery(".edited_content a[href$='.gif']").lightbox();
    jQuery(".edited_content a[href$='.png']").lightbox();

    log('lightbox enabled');
}


function enable_logging(){
	jQuery(document.body).append("<div id='log'></div>");

	jQuery(document.body).append(
		"<style type=\"text/css\">"+
			"#log {color:#888;position:absolute;top:10px;left:10px;width:200px;}"+
			"#log p {text-align:left;background:#222;padding:3px 8px;font-size:8pt;font-family:trebuchet ms,sans-serif;margin-bottom:1px;}"+
			"#log p:hover {cursor:pointer;}"+
		"</style>"
	);

    log('logging enabled');
}

function log(msg){
	//write the log message
	jQuery("#log").append('<p>'+ msg +'</p>');

	//enable on-click remove log message
	jQuery("#log p").click(function(){
		jQuery(this).remove();
	});
}

function enable_facebox(){
	jQuery("a[rel*=facebox]").facebox();
	jQuery("a.facebox").facebox();
	log("facebox enabled");
}


//extend jquery with a preload image function
jQuery.preloadImages = function()
{
    log('preload '+ arguments.length +' imges');
    for(var i = 0; i<arguments.length; i++)
    {
	    log((i+1) + ': ' + arguments[i]);
        jQuery("<img />").attr("src", arguments[i]);
    }
}

jQuery.log = function()
{
    log(arguments[0]);
}


//slideshow images
jQuery(function() {

    var slideshow_timeout = 3000;

    var $slideshow1 = jQuery('#slideshow').cycle({
        timeout:    0,
        speed:      1000,
        before:     changeCaption,
        pager:      '#thumbs',
        pagerAnchorBuilder: function(idx, slide) {
            return '#key-thumbs li:eq(' + idx + ') a';
        }
    });

    function setCaption(str) {
        jQuery('#caption').html(str);
    }

    function changeCaption() {
        jQuery('#caption').html(this.alt);
    }

    $('#package-offers').cycle('fade');

});