

/*******************************************
 *
 * JS PhotoGallery Class
 *
 * Created by Cary Buchmann June 09, 2010
 *
 * videoContainer - the div container that
 * the video object will be embedded in
 *
 * galleryContainer - the div container
 * that the galleryImages will be contained
 * in
 *
 ******************************************/



$(function(){
    var pG = new PhotoGallery();
    pG.loadData();
    
    
    $("#photo_thumbs img").live('mouseover', function(){
        $(this).css('cursor', 'pointer');
    });
    $("#photo_thumbs img").live("mousedown", function(){
        pG.hideGallery("fast");
        pG.showGallery($(this).attr("id"));
    });
    $(".popup_close_link").live('mousedown', function(){
        pG.hideGallery("slow");
    });
    $(".photogallery_thumb").live('mousedown', function(){
        var id = pG.extractUID($(this).attr("id"));
        pG.showPhoto($(this).attr("id"));
    });
    $(".close_photo").live("mousedown", function(){
        pG.hidePhoto();
    })
    
    /*if($.browser.msie){
        $("#photo_gallery_frame").css("left", 178).css("top", 567);
    }*/

})


var PhotoGallery = function()
{
    //change the urlLink to the proper location
    this.urlLink = "http://cp.inkrefuge.com/platinumstagesreciever/ajax_client.php";
    
    this.ajaxLink = this.urlLink+"?request=photos&callback=?";
    var photogallerylink = this.urlLink+"?callback=?&request=photogallery&id=";
    var photoLink = this.urlLink+"request=singlephoto&id=";
    var photoContainer = "#photo_thumbs";
    var popupWindow = "#photo_gallery_popup";
    var imageClass = "photogallery_thumb";
    var largeImageIdPrefix = "#popuplargesrc_";
    
    this.setup = function()
    {
        alert("photogallery ready");
    }
    
    this.loadData = function()
    {
        $.getJSON(this.ajaxLink, function(data) {
            var size = data.albumcover.length*165;
            if(data.albumcover.length <= 3)
                size = 500;
            var html = "<div class = 'innerThumbFrame' style = 'width:"+size+"px; height:155px;'>";
            
            var style = "margin-left:5px; margin-right:5px; height:150px;";
            
            $.each(data.albumcover, function(i, cover){
                html+="<img class = 'photogallery_image' src ='"+cover+"' id = '"+data.albumid[i]+"' style = '"+style+"'>";
            });
        html+="</div>";   
            $(photoContainer).append(html);
        });
    }
    
    this.extractUID = function(id)
    {
        var arr = id.split("_");
        return arr[1];
    }
    
    this.showGallery = function(id)
    {
        /*$(popupWindow).load(photogallerylink+id, function(){
            $(popupWindow).append("<div><a href = '#' class = 'popup_close_link popup_link'>Close</a></div>");
            $(popupWindow).fadeIn("slow");
        });*/
        $.getJSON(photogallerylink+id, function(data){
            var html = "<div class = 'images popup_images'>";
            $.each(data.thumbimage, function(i, thumb){
                html+="<img src = '"+data.thumbimage[i]+"' class = 'photogallery_image photogallery_thumb' id = '"+data.largeimage[i]+"' />";
            });
            
            html+= "<div><a href = '#' class = 'popup_close_link popup_link'>Close</a></div>";
            html+= "</div>";
            
            $(popupWindow).html(html).fadeIn("slow");
        });
    }
    
    this.hideGallery = function(speed)
    {
        $(popupWindow).fadeOut(speed);
    }
    
    this.showPhoto = function(id)
    {
        var html = "<img src = '"+id+"' class = 'show_photo' /> <br /> <div><a class = 'close_photo photo_link' href = '#'>Close</a></div>";
        $("#single_image_popup").html(html).fadeIn("fast");
    }
    
    this.hidePhoto = function()
    {
        $("#single_image_popup").html("").hide("fast");
    }
    
    this.extractUID = function(id)
    {
        var arr = id.split("_");
        return arr[1];
    }
}