window.onload = function() {
	var galleries = $$("table.gallery", "div.gallery");
	if (galleries.length) {
		var imagesetNum = 0;
		galleries.each(function(gallery) {
			var images = $A(gallery.getElementsByTagName("img"));
			images.each(function(img) {
				if (!Element.hasClassName($(img), "no-link")) {
					var lightboxLink = document.createElement("a");
					lightboxLink.setAttribute("rel", "lightbox[set" + imagesetNum + "]");

					if ($(img).getAttribute("title"))
						lightboxLink.setAttribute("title", $(img).getAttribute("title"));
					else if ($(img).getAttribute("alt"))
						lightboxLink.setAttribute("title", $(img).getAttribute("alt"));
					else 
						lightboxLink.setAttribute("title", " ");

					lightboxLink.href = $(img).src.replace(/(_t|_n)\./, '.');
					$(img).parentNode.insertBefore(lightboxLink, $(img));
					lightboxLink.appendChild($(img));
				}	
			});
			imagesetNum++;
		});
	}
};

var defined = function(A){if(typeof A=="string"){A=$(A)}return !((A==undefined&&typeof A=="undefined")||A===null)};

var popup = function(url, opts) {
	var title 	= opts['title']        	|| '';
	var width  	= opts['width']        	|| screen.width;
	var height 	= opts['height']       	|| screen.height;
	var top 	= opts['top']		|| 0;
	var left  	= (opts['left'] && !opts['centered']) ? opts['left'] : 0;
	var status 	= opts['status']       	|| 'no';
	var toolbar 	= opts['toolbar']      	|| 'no';
	var menubar 	= opts['menubar']      	|| 'yes';
	var scrollbars 	= opts['scrollbars']   	|| 'no';
	var centered 	= opts['centered']      ? opts['centered'] : 1;
	var resizable 	= opts['resizable']    	|| 'yes';
	var location 	= opts['location']    	|| 'yes';

	if (centered) {
		_left = (screen.width  - width)  / 2;
		_top  = (screen.height - height) / 2;
	} else {
		_left = _top = 0;
	}


	window.open(
		url, 
		title,
		'width=' + width + ', height=' + height + ', status=' + status +', toolbar='+toolbar+', menubar='+menubar+', scrollbars='+scrollbars+',location=' + location + ',left='+_left+',resizable=' + resizable + ',top='+_top
	);
};


getVar = function(variable) {
	var location = document.location.toString();
	if ((qmPos = location.indexOf("?")) != -1) {
		location = location.substring(qmPos+1);
		if (location.indexOf("&") != -1) {
			// found many vars
			location = location.split("&");
			for (var i = 0; i < location.length; i++) {
				if ((eqPos = location[i].indexOf("=")) != -1) {
					if (location[i].substring(0, eqPos) == variable)
						return location[i].substring(eqPos + 1);
				}
			}	
			return;
		} else {
			// url has only one var
			if ((eqPos = location.indexOf("=")) == -1)
				return; // not found = in url
			return location.substring(eqPos + 1);
		}
	}
};

function PopupBI(alink,name) 
{
	openpopup = window.open(alink, name, 'width=500, height=700, top=0, left=0, menubar=no, status=no, resizable=no, toolbar=no, location=no, scrollbars=no');
	openpopup.focus();
}


jQuery(document).ready(function(){
	jQuery.noConflict();
	jQuery(function() {
       	 jQuery("div#language select").change(function() {
       	     if (jQuery(this).val()) {
       	         window.open(jQuery(this).val(), '_self');
       	         //$("#formElement").submit();
       	     }
       	 });

	});
/*
	//Show the paging and activate its first link
	//$(".startimglink").show();
	jQuery(".startimglink a:first").addClass("active");
	jQuery(".startimglegend p:first").show();

	//Get size of the image, how many images there are, then determin the size of the image reel.
	var imageWidth = jQuery(".window").width();
	var imageSum = jQuery(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;

	//Adjust the image reel to its new size
	jQuery(".image_reel").css({'width' : imageReelWidth});

	//Paging  and Slider Function
	rotate = function(){
	    	var triggerID = jQuery.active.attr("rel") - 1; //Get number of times to slide
	    	var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

    	
    		jQuery(".startimglegend p").fadeOut('slow'); //Fade out all p
    		jQuery('.startimglegend p:eq('+triggerID+')').fadeIn('slow'); //FadeIn current p

    		//Slider Animation
    		jQuery(".image_reel").animate({
        		left: -image_reelPosition
    		}, 500 );

	};

	//On Hover
	jQuery(".image_reel img").hover(function() {
    		clearInterval(play); //Stop the rotation
	}, function() {
    		rotateSwitch(); //Resume rotation timer
	});	

	//On Click
	jQuery(".startimglink a").click(function() {
    		jQuery.active = $(this); //Activate the clicked paging
    		//Reset Timer
    		clearInterval(play); //Stop the rotation
    		rotate(); //Trigger rotation immediately
    		rotateSwitch(); // Resume rotation timer
    		return false; //Prevent browser jump to link anchor
	});
*/	
})

/*
//Rotation  and Timing Event
rotateSwitch = function(){
    play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
        jQuery.active = jQuery('.startimglink a.active').next(); //Move to the next paging
        if ( jQuery.active.length === 0) { //If paging reaches the end...
            jQuery.active = jQuery('.startimglink a:first'); //go back to first
        }
        rotate(); //Trigger the paging and slider function
    }, 3000); //Timer speed in milliseconds (7 seconds)
};

rotateSwitch(); //Run function on launch
*/
/*
			   
        a = window.location.pathname.split('/');

	alert($('div#language select option'));

	if($('div#language select option')[1].val()==a[1])
	{
		
	}
	
	
	$('div#language select').live('change', function(){
		var lang = $("option:selected", this).val();
		var lang2 = $(this).children('option').val();
		alert (lang2);
		window.open(window.location+$(this).val(), '_self');
	})
*/
/*
distributeCategoryLinks("#menu2", "#menu2 li");

function distributeCategoryLinks(container, links) 
{
	var containerWidth = $(container).width();
	alert(containerWidth);
	var listWidth = 0;
	$(links).each( function () {
		listWidth = listWidth + $(this).width();
	});
	var distance = containerWidth - listWidth;
	i = 1;
	$(links).each( function () {
	var oneDistance = Math.floor( distance/($(links).length - i) );
	$(this).css("margin-right", oneDistance);
	distance = distance - oneDistance;
	i++;
	} );
}

*/





















