var j = jQuery.noConflict()

j(document).ready(function() {
	j("a.fb").fancybox({
		'overlayShow': true,
		'overlayColor': '#000',
		'overlayOpacity': 0.6,
		'zoomSpeedIn': 800, 
		'zoomSpeedOut':	800,
		'easingIn': 'easeOutBack',
		'easingOut': 'easeInBack',
		'hideOnContentClick': true
	})
	j("a.fbi").fancybox({
		'frameWidth':680,
		'frameHeight':180,
		'overlayOpacity': 0.5
	})
	j("a.fbs").fancybox({
		'frameWidth':540,
		'frameHeight':350,
		'overlayOpacity': 0.5,
		'zoomSpeedIn':		800, 
		'zoomSpeedOut':	500
	})
	
	j(".gimg img").fadeTo(1, 0.7);
	j(".gimg img").hover(
		function () {
			j(this).fadeTo("fast", 1)
		},
		function () {
			j(this).fadeTo("normal", 0.7)
		}
	)
	
	j('#top-link').topLink({
		min: 1500,
		fadeSpeed: 500
	})
	
	j('.jLoupe').zoom({
	})
	
	//smoothscroll
	j('#top-link').click(function() {
		j('body').animate({ scrollTop: 300 }, "slow")
		j('body').animate({ scrollTop: 0 }, 2000, "easeOutBounce")
	})
	j('#ClearFormButton').click(function() {
		alert('prd');
		j(':input','#sform')
		.not(':submit, :reset')
		.val('')
		.removeAttr('checked')
		.removeAttr('selected');
	    return false;
	});
})

//plugin topLink
jQuery.fn.topLink = function(settings) {
	settings = jQuery.extend({
		min: 1,
		fadeSpeed: 200,
		ieOffset: 50
	}, settings)
	return this.each(function() {
	//listen for scroll
		var el = j(this)
		el.css('display','none'); //in case the user forgot
		j(window).scroll(function() {
		//stupid IE hack
			if(!jQuery.support.hrefNormalized) {
				el.css({'position': 'absolute', 'top': j(window).scrollTop() + j(window).height() - settings.ieOffset})}
				if(j(window).scrollTop() >= settings.min){el.fadeIn(settings.fadeSpeed)}
				else{el.fadeOut(settings.fadeSpeed)}
			}
		)
	})
}
//zoom
jQuery.fn.zoom = function() {
	var loupe = {'width' : 300, 'height': 151};
	
	//j('<div id="thejLoupe"/>').addClass('thejLoupe').css('position','absolute').css('width',loupe.width+'px').css('height',loupe.height+'px').css('backgroundColor','rgba(0,0,0,0.25)').hide().appendTo('body');	
	//j('<div id="zoomWrapper" />').css('width',loupe.width-10+'px').css('height',loupe.height-10+'px').css('overflow','hidden').css('marginTop','5px').css('marginLeft','5px').appendTo('#thejLoupe');

	this.each(function(){
		var s = (j(this).attr('longdesc') != undefined) ? j(this).attr('longdesc') : j(this).attr('src');
		var i = j('<img />').bind('load',function(){
				j(this).data('size',{'width':this.width, 'height':this.height});
			}).attr('src', s).hide().appendTo('#zoomWrapper');	
		j(this).data('zoom',i);		
	})
	.bind('mousemove', function(e){ 
		var o = j(this).offset();
		var i = j(this).data('zoom');
		//j('#thejLoupe').css('left',e.pageX+10).css('top',e.pageY+10);
		var zlo = ((e.pageX - o.left) / this.width) * j(i).data('size').width - (loupe.width/2) -130;
		var zto = ((e.pageY - o.top) / this.height) * j(i).data('size').height - (loupe.height/2) - 14;
		j(i).css('marginLeft', zlo * -1 + 'px').css('marginTop', zto * -1 + 'px').show();
	})
	.bind('mouseout', function(e){
		j(this).data('zoom').hide();
		j('#zoomWrapper').css('backgroundImage', "url(/images/loupe.jpg)")
		//j('#thejLoupe').hide();
	})
	.bind('mouseover', function(e){
		j(this).data('zoom').show();
		j('#zoomWrapper').css('backgroundImage', 'none')
		//j('#thejLoupe').show();
	});
}
