jQuery(document).ready(function() {
	$j = jQuery.noConflict();
	var currentImageIndex = -1, imageIndexes = Array(), params2 = Array(), windowHeight = 0, windowWidth = 0;
/*	if ($j.browser.safari) {                                               
		$j(window).load(function(){
			setImagesWidth();
			setTimeout(function() { setImagesWidth(); }, 400);
		});
	} else {
		setImagesWidth();
		setTimeout(function() { setImagesWidth(); }, 400);
	}
	
	function setImagesWidth() {
		$j(".galleriPic").each(function() {
			$j(this).parent().css('width', $j(this).width()*(150/parseInt($j(this).css("height"))));	
		});
	}
		*/
	$j(".galleriPic").hover(function(objectEvent) {
		$j(this).css({'z-index': '10', "position": "absolute"});
		$j(this).stop().animate({
			marginTop: '-50px', /* The next 4 lines will vertically align this image */ 
			marginLeft: '-31%',
			top: '25%',
			left: '25%',
			height: '175px' /* Set new height */
//			padding: '30px'
		},175);
		
	}, function(objectEvent) {
		$j(this).stop().animate({
			marginTop: '0', /* Set alignment back to default */
			marginLeft: '0',
			top: '0%',
			left: '0%',
			height: '150px', /* Set height back to default */
			padding: '0px',
		}, 175, function() {
			$j(this).css({'z-index': '0', "position": "relative"});
		});
	}).click(function(eventObject) {
		if (window.location.search.length < 10) {
			params = $j(".first-child a")[0].href.split("?")[1].substring(1, $j(".first-child a")[0].href.length).split('&');
		} else {
			params = window.location.search.substring(1, window.location.search.length).split('&');
		}
		params2 = Array();
		$j(params).each(function(id, obj) {
			params2.push(obj.split('='));
		});
		windowHeight = document.documentElement.clientHeight - 100;
		windowWidth = document.documentElement.clientWidth - 100;
		imageName = $j(this).context.alt;
/*		TINY.box.show("?controller=image&action=showLarge&name=" + imageName + "&c=" + params2[0][1] + "&id=" + params2[2][1] + "&wh=" + windowHeight + "&ww=" + windowWidth + "&layout=image",1,0,0,1,0,function() {
			$j("#left-icon").css("top", (windowHeight/2));
			$j("#right-icon").css("top", (windowHeight/2));
/*			console.log($j("#imageHolder").css("display"));
			console.log($j("#imageHolder > img").css("display"));*/
//			$j("#totalAmoutOfPictures").html($j("#thumbs").children().length);
/*			$j("#thumbs").children().each(function(index, object) {
				imageIndexes[index] = $j(this).children()[0].alt;
				if (imageName == $j(this).children()[0].alt) {
					currentImageIndex = index;
					//$j("#currentImageNumber").html(index+1);
				}
			});
			$j("#right-icon").click(function() {
				if (currentImageIndex == imageIndexes.length-1) {
					currentImageIndex = 0;
				} else {
					currentImageIndex++;
				}
				$j.get("?controller=image&action=showLargeLight&name=" + imageIndexes[currentImageIndex] + "&c=" + params2[0][1] + "&id=" + params2[2][1] + "&wh=" + windowHeight + "&ww=" + windowWidth + "&layout=image",function(data) {
					$j("#imageHolder").html(data);
					$j("#imageHolder > img").css({
						'position' : 'fixed',
						'left': ((windowWidth-parseInt($j("#imageHolder > img").css('width')))/2) + 58
					});
					$j("#left-icon").css({
						'position' : 'fixed',
						'left': parseInt($j("#imageHolder > img").css('left'))
					});
					$j("#right-icon").css({
						'position' : 'fixed',
						'right': parseInt($j("#imageHolder > img").css('right')) - 30
					});
/*					$j("#tinybox").css('width', $j("#imageHolder > img").width());*/
				/*	$j("#imageHolder").hide(1000,function() {
						$j("#imageHolder").html(data).show(400);	
					});*/
/*				});
			});
			$j("#left-icon").click(function() {
				if (currentImageIndex == 0) {
					currentImageIndex = imageIndexes.length-1;
				} else {
					currentImageIndex--;
				}
				$j.get("?controller=image&action=showLargeLight&name=" + imageIndexes[currentImageIndex] + "&c=" + params2[0][1] + "&id=" + params2[2][1] + "&wh=" + windowHeight + "&ww=" + windowWidth + "&layout=image",function(data) {
					$j("#imageHolder").html(data).css("height", parseInt($j("#imageHolder > img").css('height')));
					$j("#imageHolder > img").css({
						'position' : 'fixed',
						'left': ((windowWidth-parseInt($j("#imageHolder > img").css('width')))/2) + 58
					});
					$j("#left-icon").css({
						'position' : 'fixed',
						'left': parseInt($j("#imageHolder > img").css('left'))
					});
					$j("#right-icon").css({
						'position' : 'fixed',
						'right': parseInt($j("#imageHolder > img").css('right')) - 30
					});
/*					$j("#imageHolder").hide(400,function() {
						$j("#imageHolder").html(data).show(400);	
					});*/
/*				});
			});
		});
		
		*/
	});
	
/*	$j(document).keyup(function(e) {
	  if (e.keyCode == 27) { TINY.box.hide() }   // esc
	});
*/	
	
});
