// JavaScript Document

$(document).ready(function() {
	
	/* Front BBRoller */
$(rimg).bind('done', function() {
	$('#poproll').fancybox({
		'overlayColor'		:  '#007f43',
		'overlayOpacity'		:  0.9,
		'width'				: 780,
		'height'			: 305,
		'autoScale'     	: false,
		'autoDimensions' : false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'content'		: $('#poproll').html(),
		'centerOnScroll'	:	false,
		'padding'		: 0,
		'onComplete': function() {
// setTimeout(function() {
			$('#fancybox-wrap').addClass('importantRule');
			$('#fancybox-content > div').bbroller({'duration':15000});
                        // $('#poproll').find('img').load(function() {$('#fancybox-content > div').bbroller({'duration':15000})});
			$.fancybox.resize();
// }, 500);
		}
	});
	$('#poproll').trigger('click');
 });
	
	
	/* Products Grid */
						   
	$('#productsgrid li').mouseover(function(){
		$(this).stop(true,true).animate({'top':-5},'fast','linear')
	})
	$('#productsgrid li').mouseleave(function(){
		$(this).stop(true,true).animate({'top':0},'fast','linear')
	})

	$('#productsgrid li a').click(function(){

		var productimg = $(this).attr('href');
		var elem = $(this).attr('class');
		
		$('<img class="hide" id="tmpwrapper" src="'+productimg+'">').appendTo('body').load(function(){
			
			iwidth = $(this).width();
			iheight = $(this).height();
			
			$.fancybox({
				'overlayColor'		:  '#000000',
				'overlayOpacity'		:  0.7,
				'autoScale'     	: false,
				'autoDimensions' : true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'content'		: pginject(elem,iwidth,iheight),
				'centerOnScroll'	:	false,
				'padding'		: 0,
				'onComplete': function() { $.fancybox.resize(); }
			})
			
		});
		
		return false;

	});
	
	var pginject = function(classname,targetwidth,targetheight) {

		var pghtml = $($.trim($('#pgprototype').html()));
		var target = $('#productsgrid li a.'+classname);
		var productimg = target.attr('href');
		var description = target.attr('description');
		
		$(pghtml).find('.productshot img').attr('src',productimg);
		$(pghtml).find('h1').html(description).css('width',iwidth);
		$(pghtml).find('img').attr({'width':targetwidth,'height':targetheight});
		
		return pghtml;
	};
	
	var mousepointer = function() {
		
	};
	
	var maxBG = function() {
		$('#bgholder').css('width',$(window).width());
		$('#bgholder').css('height',$(window).height());
		$('#bgholder').css('top',0);
		$('#bgholder').css('left',0);
	};
	
	mousepointer();
	maxBG();
	
	$(window).resize(function() {
		maxBG();
	});
	/*
	$(document).mousemove(function(e){
		$('#pos').html(e.pageX+'    '+e.pageY)
	});
	*/
	
	/*  Map  */
	
	$('.showmap').fancybox({
			'overlayOpacity'	:	0.7,
			'overlayColor'		:	'#007f43',
			'padding'			:	0,
			'margin'				:	0,
			'width'				: 	660,
			'height'				: 	408,
			'autoScale'     	: 	true,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'					: 	'iframe'
	});
	
	$('.pagetop').click(function() { pageTop(); })
})

$(window).load(function(){
	/* Store Roller */
	$('#storeroller').storeroller();
});

/* pageTop Button */

function pageTop() {
	$('html, body').animate({scrollTop : 0},'slow');
     return false;
}

