<!--

$(document).ready(function(){
	// Load building related items
	$('#building #relatedbar .head').click(function(){
		var tpe = $(this).parents('div').attr('id');
		$('#building #relatedbar #' + tpe + ' .loading').html('Loading...');
		$('#building #relatedbar #' + tpe + ' .txt').slideToggle('normal', function(){
			var $hdr = $('#building #relatedbar #' + tpe + ' .head span');
			var key = $('#itemkey').text();
			if (key != ''){
				$('#building #relatedbar #' + tpe + ' .ajax').load('/functions/ajax/getarticlerelated.php', {'itemkey': key, 'tpe': tpe, 'src': 'building'}, function(){
					$('#building #relatedbar #' + tpe + ' ul').slideDown('slow');
					$('#building #relatedbar #' + tpe + ' .loading').slideUp('slow');
					switch (tpe)
					{
						case "hotelbox" : bindHotel();break;
						case "articlebox" : bindArticle();break;
						case "buildingbox" : bindBuilding();break;
						case "photobox" : bindPhoto(5);break;
						case "posterbox" : bindPoster(5);break;
					}
				});
			}
			if ($(this).is(':visible'))
			{
				$hdr.css('background-image','url(/img/arrowvert.png)').css('background-position','0 7px').css('font-weight','bold');
			}
			else
			{
				$hdr.css('background-image','url(/img/arrow.png)').css('background-position','0 4px').css('font-weight','');
			}
		});
  });
});

$(document).ready(function(){
	// Load picture related items
	$('#picture #relatedbar .head').click(function(){
		var tpe = $(this).parents('div').attr('id');
		$('#picture #relatedbar #' + tpe + ' .loading').html('Loading...');
		$('#picture #relatedbar #' + tpe + ' .txt').slideToggle('normal', function(){
			var $hdr = $('#picture #relatedbar #' + tpe + ' .head span');
			var key = $('#itemkey').text();
			if (key != ''){
				$('#picture #relatedbar #' + tpe + ' .ajax').load('/functions/ajax/getarticlerelated.php', {'itemkey': key, 'tpe': tpe, 'src': 'picture'}, function(){
					$('#picture #relatedbar #' + tpe + ' ul').slideDown('slow');
					$('#picture #relatedbar #' + tpe + ' .loading').slideUp('slow');
					switch (tpe)
					{
						case "hotelbox" : bindHotel();break;
						case "articlebox" : bindArticle();break;
						case "posterbox" : bindPoster(4);break;
					}
				});
			}
			if ($(this).is(':visible'))
			{
				$hdr.css('background-image','url(/img/arrowvert.png)').css('background-position','0 7px').css('font-weight','bold');
			}
			else
			{
				$hdr.css('background-image','url(/img/arrow.png)').css('background-position','0 4px').css('font-weight','');
			}
		});
  });
});

$(document).ready(function(){
	// Load article related items
	$('#article #relatedbar .head').click(function(){
		var tpe = $(this).parents('div').attr('id');
		$('#article #relatedbar #' + tpe + ' .loading').html('Loading...');
		$('#article #relatedbar #' + tpe + ' .txt').slideToggle('normal', function(){
			var $hdr = $('#article #relatedbar #' + tpe + ' .head span');
			var key = $('#itemkey').text();
			if (key != ''){
				$('#article #relatedbar #' + tpe + ' .ajax').load('/functions/ajax/getarticlerelated.php', {'itemkey': key, 'tpe': tpe, 'src': 'article'}, function(){
					$('#article #relatedbar #' + tpe + ' ul').slideDown('slow');
					$('#article #relatedbar #' + tpe + ' .loading').slideUp('slow');
					switch (tpe)
					{
						case "hotelbox" : bindHotel();break;
						case "articlebox" : bindArticle();break;
						case "photobox" : bindPhoto(4);break;
						case "posterbox" : bindPoster(4);break;
					}
				});
			}
			if ($(this).is(':visible'))
			{
				$hdr.css('background-image','url(/img/arrowvert.png)').css('background-position','0 7px').css('font-weight','bold');
			}
			else
			{
				$hdr.css('background-image','url(/img/arrow.png)').css('background-position','0 4px').css('font-weight','');
			}
		});
  });
});

function bindHotel()
{
	var key = $('#itemkey').text();
	// Go to hotel target
	$('#hotelbox .txt ul.related li').click(function(){
			var target = $(this).find('.target').text();
			window.open(target, 'hotel');
			$.get('/functions/ajax/loghotellink.php', {'src':'article_related', 'itemkey':key, 'tpe':'hotel'});
	});
	//log footer links
	$('#hotelbox ul.next a').click(function(event){
		var tpe = $(this).attr('class').substr(6);
		$.get('/functions/ajax/loghotellink.php', {'src':'article_related', 'itemkey':key, 'tpe':tpe});
	});
}

function bindArticle()
{
	// Go to article target
	$('#articlebox .txt ul.related li').click(function(){
			var target = $(this).find('.target').text();
			top.location = target;
	});
}

function bindBuilding()
{
	// Go to article target
	$('#buildingbox .txt ul.related li').click(function(){
			var target = $(this).find('.target').text();
			top.location = target;
	});
}

function bindPhoto(maxperpage)
{
	var spacing = 140;
	var loaded = false;
	var $waitThrobber = $('<img/>').attr('src', '/img/wait.gif').addClass('control').hide();
	var $enlargedPhotoBox = $('<div id="largephotobox"><span><img id="photo" /><img id="close" class="control" src="/img/closeimg.gif" /></span><div id="imgfoot"></div></div>').hide().appendTo('body');
  var $enlargedPhoto = $enlargedPhotoBox.find('img#photo');
  var $closeButton = $enlargedPhotoBox.find('img#close');
	var $footer = $("#largephotobox #imgfoot");
	var setUpPhotos = function() {
		var $photos = $('#photocarousel .related a');
		var $left = $('#photocarousel .left');
		var $right = $('#photocarousel .right');
		$photos.unbind('click');
		$left.unbind('click');
		$right.unbind('click');
		
		// Click left; scroll images right
		$left.click(function(){
			$photos.eq(0).css('left', 0);
			$photos.eq(0).animate({'left':spacing}, 'fast');
			$photos.eq(1).animate({'left':spacing * 2}, 'fast');
			$photos.eq(2).animate({'left':spacing * 3}, 'fast');
			$photos.eq(3).animate({'left':spacing * 4}, 'fast');
			$photos.eq(4).animate({'left':spacing * 5}, 'fast');
			$photos.eq($photos.length - 1).css('left', -spacing).animate({'left':0}, 'fast', function() {
				$(this).prependTo('#photocarousel .related');
				setUpPhotos();
			});
		});
		// Click right; scroll images right
		$right.click(function(){
			$photos.eq(3).css('left', spacing * 4);
			$photos.eq(0).animate({'left': -spacing}, 'fast', function() {
				$(this).appendTo('#photocarousel .related');
				setUpPhotos();
			});
			$photos.eq(1).css('left', 0);
			$photos.eq(2).css('left', spacing);
			$photos.eq(3).css('left', spacing * 2);
			$photos.eq(4).css('left', spacing * 3);
			$photos.eq(5).css('left', spacing * 5).animate({'left':spacing * 4}, 'fast');
		});
		
		//Enlarge cover when image is clicked
		$photos.click(function(event) {
			$enlargedPhotoBox.hide();
			var img = $(this).find('img').attr('src').split('t.jpg').join('s.jpg');
			var clas = $(this).find('img').attr('class').split('t').join('s');
			if (clas == 'sh'){
				defwidth = 600;defheight = 400;throbleft = 1;throbtop = 26;
			} else {
				defwidth = 400;defheight = 600;throbleft = 21;throbtop = 6;
			}
      $waitThrobber.appendTo(this).css({'left':throbleft, 'top':throbtop}).show();
			$enlargedPhoto.removeClass().addClass(clas);
			//Show large photo
			$enlargedPhoto.attr('src', img);
			var animateEnlarge = function(){
				var imgwidth = ($enlargedPhoto.width() == 0 ? defwidth : $enlargedPhoto.width());
				var imgheight = ($enlargedPhoto.height() == 0 ? defheight : $enlargedPhoto.height());
				var position = $('#photocarousel').position();
				var top = position.top - imgheight - 46;
				$waitThrobber.hide();
				$('#imgfoot').empty().css('width', imgwidth);
				$enlargedPhotoBox.css({
					'left':($('body').width() - imgwidth) /2,
					'top':top,
					'width':imgwidth + 4,
					'height':imgheight + 46
					}).fadeIn('normal', function(){
						//Get thumbed data if voted or show voting thumbs
						img = $(this).find('img').attr('src').split('t.jpg').join('s.jpg');
						$('#imgfoot').load('/functions/ajax/ratephoto2.php', {'img':img, 'tpe': 'lightbox'},function(){
							$('#imgfoot img.up').one('click', function(){
								if (document.cookie.length > 0)
								{
									$('#imgfoot').load('/functions/ajax/ratephoto2.php', {'img':img, 'tpe':'lightbox', 'rate':'up'}, function(){
									});
								}
								else
								{
									alert('Sorry, you must have cookies enabled for this functionality');
								}
							});
							$('#imgfoot img.down').one('click', function(){
								if (document.cookie.length > 0)
								{
									$('#imgfoot').load('/functions/ajax/ratephoto2.php', {'img':img, 'tpe':'lightbox', 'rate':'down'}, function(){																																
									});
								}
								else
								{
									alert('Sorry, you must have cookies enabled for this functionality');
								}
							});
						});
						$enlargedPhoto.one('click', function() {
							$enlargedPhotoBox.fadeOut();
							$('#imgfoot').empty();
					});
					
				});
				
				$closeButton.click(function(){$enlargedPhoto.click();});

				$('#largephotobox > span').hover(function () {$closeButton.show();}, function () {$closeButton.hide();});
				$enlargedPhoto.unbind();
			}
			//$enlargedPhoto.load(function(){
					animateEnlarge();
			//});
			
			event.preventDefault();
		});
		
		
		
		//position original images
		if (!loaded){
			if ($photos.length <= maxperpage)
			{
				$left.hide();
				$right.hide();
			}
			$photos.eq(0).css('left', 0);
			$photos.eq(1).css('left', spacing);
			$photos.eq(2).css('left', spacing * 2);
			$photos.eq(3).css('left', spacing * 3);
			$photos.eq(4).css('left', spacing * 4);
			loaded = true;
		}
	};
	
	setUpPhotos();
		
}

function bindPoster(maxperpage)
{
	var spacing = 185;
	var loaded = false;
	var $waitThrobber = $('<img/>').attr('src', '/img/wait.gif').addClass('control').hide();
	var $enlargedPosterBox = $('<div id="largeposterbox"><span><img id="poster" /><img id="close" class="control" src="/img/closeimg.gif" /></span><div id="posterfoot"><span><div class="size"></div><div class="price"></div></div><img id="more" class="control" src="/img/moreimg.gif" /></span></div>').hide().appendTo('body');
  var $enlargedPoster = $enlargedPosterBox.find('img#poster');
  var $closeButton = $enlargedPosterBox.find('img#close');
  var $moreButton = $enlargedPosterBox.find('img#more');
	var $footer = $("#largeposterbox #posterfoot");
	var setUpPosters = function() {
		var $posters = $('#postercarousel .related a');
		var $left = $('#postercarousel .left');
		var $right = $('#postercarousel .right');
		$posters.unbind('click');
		$left.unbind('click');
		$right.unbind('click');
		
		// Click left; scroll images right
		$left.click(function(){
			$posters.eq(0).css('left', 0);
			$posters.eq(0).animate({'left':spacing}, 'fast');
			$posters.eq(1).animate({'left':spacing * 2}, 'fast');
			$posters.eq(2).animate({'left':spacing * 3}, 'fast');
			$posters.eq(3).animate({'left':spacing * 4}, 'fast');
			$posters.eq(4).animate({'left':spacing * 5}, 'fast');
			$posters.eq($posters.length - 1).css('left', -spacing).animate({'left':0}, 'fast', function() {
				$(this).prependTo('#postercarousel .related');
				setUpPosters();
			});
		});
		// Click right; scroll images right
		$right.click(function(){
			$posters.eq(4).css('left', spacing * 5);
			$posters.eq(0).animate({'left': -spacing}, 'fast', function() {
				$(this).appendTo('#postercarousel .related');
				setUpPosters();
			});
			$posters.eq(1).css('left', 0);
			$posters.eq(2).css('left', spacing);
			$posters.eq(3).css('left', spacing * 2);
			$posters.eq(4).css('left', spacing * 3);
			$posters.eq(5).css('left', spacing * 5).animate({'left':spacing * 4}, 'fast');
		});
		
		//Enlarge cover when image is clicked
		$posters.click(function(event) {
			$enlargedPosterBox.hide();
			var img = $(this).find('div.image').text();
			var imgWidth = parseInt($(this).find('div.width').text());
			var imgHeight = parseInt($(this).find('div.height').text());
			var clas = $(this).find('img').attr('class');
			if (clas == 'th'){
				throbleft = 1;throbtop = 26;
			} else {
				throbleft = 21;throbtop = 6;
			}
      $waitThrobber.appendTo(this).css({'left':throbleft, 'top':throbtop}).show();
			var price = $(this).find('.price').html();
			var size = $(this).find('.size').html();
			var target = $(this).attr('href');
			//Show large poster
			$enlargedPoster.attr('src', img);
			$enlargedPoster.css({'width':imgWidth}, {'height':imgHeight});
			
			var animateEnlarge = function(){
				//var imgwidth = $enlargedPoster.attr('width');
				//var imgheight = $enlargedPoster.attr('height');
				var position = $('#postercarousel').position();
				var top = position.top - imgHeight - 46;
				$waitThrobber.hide();
				$('#posterfoot .size').empty();
				$('#posterfoot .price').empty();
				$('#posterfoot').css('width', imgWidth);
				$('#posterfoot .size').html(size);
				$('#posterfoot .price').html(price);
				$enlargedPosterBox.css({
					'left':($('body').width() - imgWidth) /2,
					'top':top,
					'width':imgWidth + 4,
					'height':imgHeight + 46
					}).fadeIn('normal', function(){
						
						$footer.one('click', function(){
							$enlargedPosterBox.hide();
							window.open(target, 'allposters');
						});
						$enlargedPoster.one('click', function() {
							$enlargedPosterBox.fadeOut();
					});
					
				});
				
				$moreButton.click(function(){$footer.click();});
				$closeButton.click(function(){$enlargedPoster.click();});
			
				$($footer).mouseover(function () {$moreButton.show();});
				$('#largeposterbox').mouseleave(function () {$moreButton.hide();});
				$('#largeposterbox > span').hover(function () {$closeButton.show();$moreButton.hide();}, function () {$closeButton.hide();});
				$enlargedPoster.unbind();
			}
			
			//$enlargedPoster.load(function(){
					animateEnlarge();
			//});
			
			event.preventDefault();
		});
		
		
		
		//position original images
		if (!loaded){
			if ($posters.length <= maxperpage)
			{
				$left.hide();
				$right.hide();
			}
			$posters.eq(0).css('left', 0);
			$posters.eq(1).css('left', spacing);
			$posters.eq(2).css('left', spacing * 2);
			$posters.eq(3).css('left', spacing * 3);
			$posters.eq(4).css('left', spacing * 4);
			loaded = true;
		}
	};
	
	setUpPosters();
		
}


//-->