var minHeight; // Altezza minima della pagina
var maxHeight; // Altezza massima della pagina
var home = false;
var start = true;

$(document).ready(function(){
	var ie6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

	//cycle image
	$('#rotate_object').cycle({
		fx:		'flash',
		timeout:5000,
		speed:	1000,
		height:	250,
		width:	255,
		pause:	true,
		random:	true,
		fit:	true
	});
	
   	jQuery.fn.cycle.transitions.vmtrans=function(d,e,f){
      	d.css('overflow','hidden');
      	f.before.push(function(a,b,c){
         	jQuery(this).show();
         	c.cssBefore.left=0-b.offsetWidth;
         	c.cssBefore.opacity=1;
         	c.cssBefore.zIndex=1;
         	//c.animOut.opacity=1;
         	//c.animOut.left=a.offsetWidth
         	c.animOut.opacity=0;
         	c.animOut.zindex=10;
      	});
      	f.cssFirst={left:0, opacity:1, zIndex:1};
    	f.animIn={left:0}
   	};
	
	//cycle image
	$('.bigimg .images').cycle({
		fx:		'vmtrans',
		timeout: 5000,
		speed:	1000,
		height:	200,
		width:	134,
      	sync:    false,
		pause:	false,
		random:	true,
		fit:	true
	});

	//cycle image
	$('.singlerotate').cycle({
		fx:		'scrollLeft',
		timeout:5000,
		speed:	3000,
		height:50,
		width:50,
		pause:	true,
		random:	true,
		fit:	true
	});



	$('.auction_list').click(function(){document.location=$('a',this).attr('href')}).css('cursor','pointer');


	$(window).resize(function(){
		if (start){
			return;
		}

		var winh = $(window).height();
		if($.browser.opera){
			winh = window.innerHeight;
		}
		var hhh = home ? 100 : 182;

    	maxHeight = winh - hhh - (($('.wrapper:eq(2)').height() != null) ? $('.wrapper:eq(2)').height() + 30 : 0) ;

    	console.debug(winh + ' = ' +maxHeight + ' > ' + minHeight);

		if(maxHeight > minHeight)
			$('#wrapper').height(maxHeight);
		});

		$(".jqzoom").click(startZoom);

		$(".tablesorter").tablesorter({headers:{5:{sorter:false}}});
		$("input#birthday").calendar({timeSeparators:false, dateFormat:"DMY/", yearRange:'1900:2020'});

		$("input[type=text], textarea", '#contact_form')
			.hover(
				function(){$(this).addClass('hover');},
				function(){$(this).removeClass('hover');}
			)
			.focus(function(){$(this).addClass('focus')})
			.blur(function(){$(this).removeClass('focus')});

			$('.zoomify')
			.css('top', $('img[jqimg]:eq(0)').height()- $('.zoomify').height() )
			.click (function(){
				startZoom();
				$(this).hide();
			})
			.hover(
				function(){$(this).addClass('zoomifyOver');},
				function(){$(this).removeClass('zoomifyOver');}
			);

			$('.lastAuction a, div.pdf a').each(function(){
				var href = $(this).attr('href');
				$(this).parent().click(function(){
					document.location = href;
				}).css('cursor','pointer');/*.hover(function(){
				$(this).animate({color:'#900',backgroundColor:'#eee'},200);
				},function(){
				$(this).animate({color:'#000',backgroundColor:'#fff'},200);
				});*/
			});

			$('.buttoncancel, .button').hover(function(){
				$(this).css({backgroundPosition:'0 -17px'});
			},function(){
				$(this).css({backgroundPosition:'0 0'});
			});
	
			$('.submit, .buttonsave').hover(function(){
				$(this).css({backgroundPosition:'0 -40px', color:'#c04649'});
			},function(){
				$(this).css({backgroundPosition:'0 0', color:'#000'});
			});
	
			$('.download, .newsletter').click(function(){
				document.location = $('a', this).attr('href')
			}).css('cursor','pointer').hover(
				function(){$(this).addClass('download_over');},
				function(){$(this).removeClass('download_over');}
			);

			$('#browse_crag').prepend($.ajax({url: '/'+translation.language+"/auth/getLinks/", async: false, cache: false}).responseText);
	
			var timeBlinking = 1500;
			if ($('.blink').length>0){
				setInterval(function(){$('.blink').fadeTo(timeBlinking/2, 0).fadeTo(timeBlinking/2, 1)},timeBlinking);
			}

			if ($('.nextprevlot a').length > 0){
				$('.nextprevlot a').click(function(){
					parent.changeTitle('');
				});
				if (parent != document){
					var title = $('.object_content h2').text();
					title+= ' - '+ $('.object_content td:first').text();
					parent.changeTitle(title);
				}
			}
			$(".show_tooltip").tooltip();
   			setTimeout(delayedLoad, 100);
	});
