/*******************************************************************************
File: ch_cust.js
Author: PICODELIQ Design Studio
Description: Custom jQuery scripts for portfolio gallery effects
Version: 0.01 - 20090927
Date: 27 Sep 2009
*******************************************************************************/

//Function to initialise the main image to a width of 600px with variable height
function initFolio() {
    var myImg = new Image();
    var theImg = "#img-main img.folio-main";
    var fixTitle = $("#img-main p.folio-main").text();
    $(theImg).removeAttr("height"); //Remove the height attribute
    $(theImg).removeAttr("width"); //Remove the width attribute

    $("#img-main p.folio-main").html(fixTitle); //Enable the HTML elements in the image caption

    //Change the main image on the click of a thumbnail
    $("#sidebar-1 .cat-list .img-thumbs a.folio-thumb").click(function(event) {
        event.preventDefault();

        var imgURL = $(this).attr("href"); //Get image URL
        var imgTitle = $(this).find("img.folio-thumb").attr("title"); //Get image title via child img tag
        var imgLink = $(this).attr("href");	//Use the same image URL to build new link to image href

        //Fade out current image and caption
        $("#img-main *.folio-main").fadeOut("fast", function(){ //500ms

           $("#img-main p.folio-main").html(imgTitle); //Replace current caption

           myImg.src = imgURL; //Load new image

           $(myImg).load(function(){

              $(this).hide(); //Hide new image

              //If height >= 500px ...
              if (myImg.height > "499") {
                 //then add a height of 500px, remove width, update src attribute
                 $(theImg).attr("height","500").removeAttr("width").attr("src",imgURL).attr("alt",imgTitle).attr("title",imgTitle);
              } else {
                 //else add a width of 600px, remove height, update src attribute
                 $(theImg).attr("width","600").removeAttr("height").attr("src",imgURL).attr("alt",imgTitle).attr("title",imgTitle);
              }

              $("#img-main *.folio-main").fadeIn(1500); //Fade in all elements of #img-main
              
              //GFBO 20100719 Modify the original image URL for new 'Link to this image' format
              //              Then replace the 'Link to this image' link
              $("#img-main-link a").attr("href",imgLink.replace('images\/','portfolio?imgidno=').replace(/\.jpg/i,''));

           }); //$(myImg)

        }); //$("#img-main *.folio-main")

        return false;
    });

    //Use lightbox plug-in
    $("#sidebar-1 a.folio-ltbx").lightBox();

    return false;
}

