$(document).ready(function(){
	$.ifixpng('/img/pixel.gif');
	$('.logo,.home-image').ifixpng(); 
	var interval;
	var currentItem = 0;
	var animating = false;
	var slides = $("#front-content .box-blue").find('span');
	slides.children().each(function() {  		
			$(this).parent().hide();	
			var firstImage = $(this).parent().children().first();		
			firstImage.attr('first',1);			
			$(this).parent().parent().css({ 'background-image': 'url('+firstImage.attr('src')+')' });								
	});
	
	$("#front-content .box-blue").hover(
	      	function () {
				var obj = $(this);
				var photos = new Array();
				var slideshowSpeed = 500;
				var slides = $(this).children().next().children();	
				clearInterval(interval);
				if(slides.length > 0) {				
					interval = setInterval(function() {
									navigate(obj,slides);
									}, slideshowSpeed);	
				}							
			},
			function () {
				clearInterval(interval);
				currentItem = 0;
				animating = false;
				var slides = $(this).find('span');
				slides.children().each(function() { 
					if(typeof($(this).attr('first')) != 'undefined') {				
						$(this).parent().parent().css({ 'background-image': 'url('+$(this).attr('src')+')' });
					}																	
				});
			}
	);
	
	var navigate = function(obj,photos) {
		if(!animating) {
			currentItem = currentItem + 1;
		}		
		animating = true;
		var prevItem = currentItem -1;	
		if (prevItem < 0) {
			prevItem = photos.length - 1;
		}
		
		var item = photos[currentItem];
		if(typeof(item) != 'undefined') {
			obj.css({ 'background-image': 'url(\''+item.src+'\')' });
		}
		
		currentItem = currentItem + 1;
		if(currentItem >= photos.length) {
			currentItem = 0;
		}
	};
		
	$('#product').codaSlider({
        autoSlide: false,
        autoSlideStopWhenClicked: true,
        dynamicArrowLeftText: '',
        dynamicArrowRightText: '',
        dynamicTabs:false,
		dynamicArrows: false
    });
	$('.product-slides').loopedSlider();
	$("#fancy-frame").fancybox({'width': '97%','height': '97%','autoScale': false,'transitionIn': 'none','transitionOut': 'none','type': 'iframe','hideOnOverlayClick' : false});	
});


var popupWindow = function (mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',location=0,status=0,toolbar=0,scrollbars='+scroll+',notresizable'
	win = window.open(mypage, myname, winprops)
	if (win.opener == null) { win.opener = self }
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

