jQuery(document).ready(function() {
	//Load SWF
	swfobject.embedSWF(jsAppPath + "Includes/620x197.swf", "bannerImage", "620", "197", "9.0.0");
	
	//PNG Fix
	jQuery(document).pngFix(); 
	
	//Setup Gallery
	setupPhotoGallery();	
	
});

function galleryOnBefore(curr,next,opts) {
    var jQueryslide = jQuery(next);
    var w = jQueryslide.outerWidth();
    var h = jQueryslide.outerHeight();
    
    if (w <= 603)
    {
        jQueryslide.css({
            marginTop: (452 - h) / 2,
            marginLeft: (603 - w) / 2
        });
    }
};


function setupPhotoGallery()
{
    jQuery("#slideshow-videos").hide();
    jQuery('.slideshow-img').html('');
    jQuery('.slideshow-thumbs').html('');
    
    jQuery(".video").removeClass("video_active");
    jQuery(".photo").addClass("photo_active");

    var images = "";
	jQuery.each(jQuery("#slideshow-photos li"), function() {
        
        images += "<img src='" + jQuery("span",this).text() + "' />";
            
    });
    
    jQuery('.slideshow-img').append(images);
    
    jQuery('.slideshow-img').cycle({ 
        fx:     'fade', 
        speed:  'slow', 
        timeout: 0, 
        next:   '.slideshow-next', 
        prev:   '.slideshow-prev',
        width:  603,
        height: 452,
        before: galleryOnBefore,
        pager:  '.slideshow-thumbs',
        // callback fn that creates a thumbnail to use as pager anchor 
        pagerAnchorBuilder: function(idx, slide) { 
            return '<li><a href="#"><img src="' + slide.src + '" width="50" height="50" /></a></li>';
            }
    });
}

function setupVideoGallery()
{
    jQuery("#slideshow-videos").hide();
    jQuery('.slideshow-img').html('');
    jQuery('.slideshow-thumbs').html('');
    
    jQuery(".photo").removeClass("photo_active");
    jQuery(".video").addClass("video_active");
    
    jQuery('.slideshow-img').append(jQuery("#slideshow-videos").html());
    
    jQuery('.slideshow-img').cycle({ 
        fx:     'fade', 
        speed:  'slow', 
        timeout: 0, 
        next:   '.slideshow-next', 
        prev:   '.slideshow-prev',
        width:  603,
        height: 452,
        before: galleryOnBefore,
        pager:  '.slideshow-thumbs',
        // callback fn that creates a thumbnail to use as pager anchor 
        pagerAnchorBuilder: function(idx, slide) { 
            return '<li><a href="#"><img src="' + slide.className + '" width="50" height="50" /></a></li>';
            }
    });
}

function slideRight()
{
    var count = jQuery(".slideshow-thumbs li").length;
    var currentsize = 80 * count;
    var left = jQuery(".slideshow-thumbs").css("left").replace('px','');
    if (left == null || isNaN(left)) { left = 0; }
    left = parseInt(left) - 564;
    var leftPos = Math.abs(left);
    var leftPx = left + 'px';
    
    if (currentsize > 564 && leftPos <= currentsize)
    {
        jQuery(".slideshow-thumbs").animate({left:leftPx},2000);
    } 
}

function slideLeft()
{
    var count = jQuery(".slideshow-thumbs li").length;
    var currentsize = 80 * count;
    var left = jQuery(".slideshow-thumbs").css("left").replace('px',''); 
    if (left == null || isNaN(left)) { left = "0"; }
    
    if (left != "0")
    {
        left = parseInt(left) + 564; //alert(left);
        var leftPos = Math.abs(left); 
        var leftPx = left + 'px';
        
        if (currentsize > 564 && leftPos <= currentsize)
        {
            jQuery(".slideshow-thumbs").animate({left:leftPx},2000);
        }
    } 
}