var PageConfig={
		GalleryPageSize:8,
		WebRoot:'/',
		ImageLibRoot:'/',
		GalleryThumbWidth:78,
		GalleryThumbHeight:58,
		GalleryWidth:345,
		GalleryHeight:258
};

$(document).ready(function(){
	PageConfig.WebRoot=$('#web_root').val();
	PageConfig.ImageLibRoot=$('#imagelib_root').val();
		
	$('.hilitebutton').mouseover(function(){
		this.style.backgroundColor=$('#hiliteButtonColor').val();
	});
	
	$('.hilitebutton').mouseout(function(){
		if(!$(this).hasClass('activetab') && !$(this).hasClass('activebutton'))
			this.style.backgroundColor=$('#buttonColor').val();
	});
	
	$('#main-nav .hilitebutton').trgfieldHint(function(el){return el;},'tooltip');
});

function setTab(listingId,tabName)
{
	var old=$('#listing-'+listingId+' .activetab');
	var newt=$('#listing-'+listingId+' .'+tabName+'-tab');
	
	old.removeClass('activetab');
	old.addClass('normtab');
	old.css('background-color',$('#buttonColor').val());
	
	newt.addClass('activetab');
	newt.removeClass('normtab');
	newt.css('background-color',$('#hiliteButtonColor').val());
		
	var content=$('#listing-'+listingId+' .body');
	content.empty();
	
	if(tabName=='images')
	{		
		$('#listing-'+listingId+' .nongallery').hide();		
		$('#gallery-'+listingId).show();
		
		if(!$('#gallery-'+listingId).get(0).gal_init)
		{
			$('#gallery-'+listingId).get(0).gal_init=true;
			
			var gallery = $('#gallery-'+listingId).adGallery({
				  loader_image: PageConfig.WebRoot+'images/ad-gallery/loader.gif',
				  width: false, // Width of the image, set to false and it will read the CSS width
				  height: false, // Height of the image, set to false and it will read the CSS height
				  thumb_opacity: 0.7, // Opacity that the thumbs fades to/from, (1 removes fade effect)
				                      // Note that this effect combined with other effects might be resource intensive
				                      // and make animations lag
				  slideshow : {enable:true,
				  	speed: 3000},
				  start_at_index: 0, // Which image should be displayed at first? 0 is the first image
				  animate_first_image: false, // Should first image just be displayed, or animated in?
				  animation_speed: 400, // Which ever effect is used to switch images, how long should it take?
				  display_next_and_prev: true, // Can you navigate by clicking on the left/right on the image?
				  display_back_and_forward: true, // Are you allowed to scroll the thumb list?
				  scroll_jump: 0, // If 0, it jumps the width of the container
				  effect: 'none', // or 'slide-vert', 'resize', 'fade', 'none' or false
				  enable_keyboard_move: true, // Move to next/previous image with keyboard arrows?
				  cycle: true // If set to false, you can't go from the last image to the first, and vice versa
				});		
		}
	}
	else
	{
		$('#listing-'+listingId+' .nongallery').show();		
		$('#gallery-'+listingId).hide();
		
		$.ajax({url:window.location.href,
			data:{
				ajaxMethod:'getContent',
				tab:tabName,
				id:listingId
			},
			success:function(data,textStatus){
				if(data.success)
					content.html(data.html);
			},
			error:function(req,textStatus,errorThrown){
				alert('There was an error processing the request');
			},
			type:'POST',
			dataType:'json'
		});
		
		if (tabName == 'map')
		{
			$('#image-'+listingId).hide();
			$('#map-'+listingId).show();
			$('#printbutton-'+listingId).show();
		}
		else
		{
			$('#image-'+listingId).show();
			$('#map-'+listingId).hide();
			$('#printbutton-'+listingId).hide();
		}
	}
}
