$(function() {
    Utility.init();
});

var Utility = {

    gallery: [],
    activeGraphic: -1,
    activeGallery: 'none',
   
   init: function() {},
  
   openGallery: function(galleryName) {
	$('#frmMain')[0].src = "pages/galleryViewer.php?gallery=" + galleryName;
	this.activeGallery = galleryName;
   },
     
    openGraphic: function(id) {
    	var objectID;
    	if(id < this.gallery.length && this.gallery[id] != undefined)
    	{
    	    this.activeGraphic = id;
    	    objectID = this.gallery[id];
    	    if(objectID.indexOf(",") > 0)
    	    {
    	    	var id1 = objectID.substr(0,objectID.indexOf(","));
    	    	var id2 = objectID.substr(objectID.indexOf(",") + 1);
    	    	this.openDoubleGraphic(id1, id2);
    	    }
    	    else
    	    {
	    	$('#frmMain').attr("src", "pages/fullSizeViewer.php?id=" + objectID);    
	    }
    	}
    	else
    	{
    	    alert('This image or video is not available for viewing at this time.');
    	}
    },

    openDoubleGraphic: function(id1, id2) {
    	$('#frmMain').attr("src", "pages/fullSizeViewer.php?id=" + id1 + "&secondId=" + id2);  
    },
       
    nextGraphic: function()
    {
    	this.activeGraphic ++;
    	if(this.activeGraphic == this.gallery.length)
    	    this.activeGraphic = 0;
    	
    	this.openGraphic(this.activeGraphic);
    }, 
   
    previousGraphic: function()
    {
    	this.activeGraphic --;
    	if(this.activeGraphic < 0)
    	    this.activeGraphic = this.gallery.length - 1;
    	
    	this.openGraphic(this.activeGraphic);
    }, 

    returnToGallery: function() {
        this.openGallery(this.activeGallery);
    },
    
    openBlog: function() {
    	$('#frmMain').attr("src", "http://www.jkfproductions.wordpress.com");
    },
    
    openHome: function() {
    	var rand = Math.round(Math.random()*1000);
    	$('#frmMain').attr("src", "pages/homeGraphic.php?rand=" + rand);
    },
    
    openVimeo: function() {
    	$('#frmMain')[0].src = "http://vimeo.com/jkfproductions/videos";
    
    },
    
    openBlogSpot: function() {
    	$('#frmMain').attr("src", "http://jkfproductions.blogspot.com/");
    
    },
    
    openLinkedIn: function() {
    	$('#frmMain').attr("src", "http://www.linkedin.com/pub/joe-fuller/15/816/75a");    
    },
    
    openContact: function() {
    	$('#frmMain').attr("src", "pages/contact.html");    
    }
}
