jQuery(function() {
	/*GENERAL*/
	if(jQuery('.boxRight').length) jQuery('.boxLeft').css('width','476px') 
	else{ jQuery('.boxLeft').css('width','745px'); jQuery('.boxes').attr('id','specialbox'); }
	
	/*PRELOAD*/
		jQuery('#thumbs li a').each(function() { 
		    var reference=jQuery(this).attr('href');
		    img=new Image;
		    img.src=""+reference+"";
		});
	
	/*GALLERY CLICK ON THUMBNAIL*/
	jQuery('#gallery #thumbs li:first').addClass('on');
	jQuery('#thumbs li a').click(function() { 
			if(jQuery(this).parents('#gallery2').length) {
				if(jQuery(this).parent().is('.on')) { return false; }
				else {	
				jQuery(this).css('opacity',0);
				jQuery('#thumbs li.on a').css('opacity',0.7);
				}
			}
			jQuery('#thumbs li').removeClass('on');
			jQuery(this).parent().addClass('on');
			var source=jQuery(this).attr('href'); 
			
			image = new Image();
    			var temp = source;
        		image.src = temp;
			
			if(image.width>0){
			    var width = image.width;
			}else{
			    var width = 10;
			}
			
			if(image.height>0){
			    var height = image.height;
			}else{
			    var height = 10;
		        }
			
			jQuery('#bigpic img').hide();
			jQuery('#bigpic img').attr('src', source).fadeIn(400);
			jQuery('#bigpic img').attr('width', width);
			jQuery('#bigpic img').attr('height', height);
			
			title();
			return false;	
	});
	
	jQuery('#gallery2 #thumbs li a').css('opacity',0.7);
	jQuery('#gallery2 #thumbs li:first a').css('opacity',0).parent().addClass('on');
	jQuery('#gallery2 #thumbs li a')	
		.mouseover(function() { jQuery('#gallery2 #thumbs li[@class!="on"] a').css('opacity',0.7); jQuery(this).fadeTo('fast', 0); })
		.mouseout(function() { if(!jQuery(this).parent().is('.on')) { jQuery(this).fadeTo('fast',0.7); } 
	}); 
	
	/*GALLERY CLICK ON PREVIOUS*/
	jQuery('#thumbs .prev').click(function() { 
		if(jQuery('#thumbs li.on').is(':first-child')) { 
			jQuery('#thumbs li.on').removeClass();
			jQuery('#thumbs li:last-child').addClass('on');
			jQuery('#thumbs .on a').trigger('click') 
		}
		else {
			jQuery('#thumbs .on').prev().addClass('on').end().removeClass();  
			jQuery('#thumbs .on a').trigger('click') 
		}	
		title();
	});
	
	/*GALLERY CLICK ON NEXT*/
	jQuery('#thumbs .next').click(function() { 
		goNext();
	});
	
	/*PICTURE TEXT*/
	jQuery('div.picTitle').text(jQuery('#thumbs li:first img').attr('title'));
	
	/*SLIDESHOW INIT*/
	if(jQuery('#gallery #thumbs').length > 0) { var x=setTimeout("slideShow()", 3500); }
	
	/*RIGHTBOXES*/
	jQuery('.picBox').mouseover(function() { jQuery(this).next('.boxtitle').addClass('boxtitle_over'); })
				.mouseout(function() { jQuery(this).next('.boxtitle').removeClass('boxtitle_over'); })
				
	/*HEADERS*/
	jQuery('.boxTop .innerBox a.outdoor').prependTo('.boxTop');
	jQuery('.boxTop .innerBox a.indoor').prependTo('.boxTop');
	jQuery('.boxLeft .innerBox h1:first').prependTo('.boxLeft');
	jQuery('.boxRight .innerBox h1:first').prependTo('.boxRight');
	jQuery('.boxTop .innerBox h1:first').prependTo('.boxTop');
	jQuery('.boxBottom .innerBox h1:first').prependTo('.boxBottom');

	/*LINKS*/
	jQuery('.print a').click(function() { PrintLink(); return false; })
	
	/*PRINTPAGE*/
	var url=document.location.href.toString();
	if((url.indexOf('?print')>0) || (url.indexOf('&print')>0))  { 
		jQuery('form').each(function() { 
			var action= jQuery(this).attr('action').toString(); 
			if(action.indexOf('?')>0) { jQuery(this).attr('action',action+'&print=1');  }
			else  { jQuery(this).attr('action', action+'?print=1'); }
		});	
		jQuery('a').each(function() { 
			var location=this.href.toString();
			console.log(location);
			if(location.indexOf('?')>0) { jQuery(this).attr('href', jQuery(this).attr('href')+'&print=1'); }
			else  { jQuery(this).attr('href', jQuery(this).attr('href')+'?print=1'); }
		}); 
	}
	
	jQuery('.tx_powermail_pi1_form fieldset:odd').after('<div style="clear:both"></div>');
	
});

function setWidthHeight() {
    
}

function slideShow() { x=setTimeout('slideShow()', 3500); goNext(); jQuery('#thumbs a').click(function() {  clearTimeout(x); x=setTimeout('slideShow()', 3500); })  }
function goNext() { 
	if(jQuery('#thumbs li.on').is(':last-child')) { 
	jQuery('#thumbs li.on').removeClass();
	jQuery('#thumbs li:first-child').addClass('on');
	jQuery('#thumbs .on a').trigger('click') 
	}
	else {
		jQuery('#thumbs .on').next().addClass('on').end().removeClass();  
		jQuery('#thumbs .on a').trigger('click') 
	}	
	title();
}
function title() { 
	var tit=jQuery('#thumbs li.on img').attr('title');
	jQuery('div.picTitle').text(tit);
}
function showInfo() { 
	if(jQuery("#addressId").length) {
		var addressId = jQuery("#addressId").text();
		jQuery('.tx-ttaddress-pi1 ul li').hide();
		jQuery('.tx-ttaddress-pi1 ul li div[@class*=vcard'+addressId+']').parent().show();
	}
};