/*
 * image gallery using jQuery and Interface - http://www.getintothis.com
 * 
 * note: this library depends on jQuery (http://www.jquery.com) and
 * Interface (http://interface.eyecon.ro)
 *
 * Copyright (c) 2006 Ramin Bozorgzadeh
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LECENSE.txt) linceses.
 */

$.fn.gallery = function(options) {
    var self = this;

    self.options = {
        imageHolderClass: 'image_holder'+document.getElementById('pgControl').value,
        reflection: true,
        thumbs: true,
        thumbsDimension: 50,
        thumbsBorderWidth: 2,
        naviconWidth: 50,
        triggerHeight: 25
    };

    // make sure to check if options are given!
    if(options) {
        $.extend(self.options, options);
    }

    this.each(function() {
        var g = this;
		//alert( g.id);
        var reflection_height = (self.options.reflection) ? 60 : 0;
		var imgHoldernew= document.getElementById('image_holderid' + document.getElementById('pgControl').value);
        imgHoldermew =  $('#' + g.id + ' .' + self.options.imageHolderClass)[0];
		//alert(imgHoldernew)
        g.swapping_image = false;
       
        g.init_gallery = function(imgs,first) {
			
				//alert(g.id);
	        g.imgs = imgs;
			var imgHoldernew= document.getElementById('image_holderid' + document.getElementById('pgControl').value);
			var imageHolderClassnew  = 'image_holder'+document.getElementById('pgControl').value;
			imgHoldermew =  $('#' + "gallery-" + document.getElementById('pgControl').value + ' .' + imageHolderClassnew)[0];
	
            g.image = $(imgHoldermew).find('img')[0];
			g.image_index = 0;
     
            //$(imgHoldermew).height($(g.image).offset().height + reflection_height + 'px');
           g.swap_image(g.imgs.split(",")[0],first, function() {
           });
		
			
        }



      
        
        /*
         * funtion to swap images
         */
        g.swap_image = function(new_img_src,first, callback) {
			try
			{				
			
            var orig_img_width = g.image.width;
            var new_img = new Image();
           //alert(1);
            g.swapping_image = false;
            //$(new_img).addClass('swap');
           var imgName = "<img id='imgHolder" + document.getElementById('pgControl').value + "'" + "alt='' src='" +new_img_src + "'/>" 
                    
					document.getElementById('image_holderid'+document.getElementById('pgControl').value).innerHTML = imgName;
                    // remove the reflection
                   
          
            new_img.src = new_img_src;
			return;
			}
			catch (ex)
			{
				 alert("error");
			}
        }

        

    });


    if(this.size() == 1) {
        return this[0];
    } else {
        return this;
    }
};
