(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);

function goToPage(page)
{
	window.location.href = page;
}

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$(document).ready(function($){

	$('#catnav li a:not(.active)')
		.css( {backgroundPosition: "-10px 18px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(10px 18px)"}, 300);
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-10px 18px)"}, 100)
		});

	$('#nav li a:not(.active)')
		.css( {backgroundPosition: "0 35px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -260px)"}, 300);
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 35px)"}, 200)
		});

	$(".sideblockdiv").click(function () {
     	if($(this).find('a').attr("href")){
     		window.location = $(this).find('a').attr("href");
     	}
    });

	/*// set opacity to nill on page load
	$("ul#nav li a").css("opacity","0");
	// on mouse over
	$("ul#menu li a").hover(function () {
		// animate opacity to full
		$(this).stop().animate({
			opacity: 1
		}, "slow");
	},
	// on mouse out
	function () {
		// animate opacity to nill
		$(this).stop().animate({
			opacity: 0
		}, "slow");
	});*/

	$('.filter-dropdown').change(function() {
		cookie_name = $(this).attr('id');
		cat_id = $("option:selected", this).attr('id').replace('cat-','');
		$.cookie(cookie_name, cat_id, { expires: 7, path: '/' }); // save dropdown
		$.cookie('exp_category', cat_id, { expires: 7, path: '/' }); // save current category
		window.location = $(this).val();
	});

	if($.cookie('filter_category')!=1 && $('#filter_category').val()=='-') {
		cat = 'cat-'+$.cookie('filter_category');
		$('#filter_category option[id='+cat+']').attr("selected", true);
	}

	//$(".filter-menu select").bind("change", filter_object_page);

	$('#sfeer').cycle({ 
    fx:    'fade', 
    timeout:  1500,
    speed: 3500 
	});

	$('#product-image').cycle({ 
    fx:    'fade', 
    speed: 1000,
   	pager:  '#slider-nav',
	pauseOnPagerHover: 1 
	});
	
	/*$('#sfeertext').cycle({ 
    fx:    'fade', 
    timeout:  1500,
    speed: 3500,
    cleartypeNoBg: true,
    cleartype: true
	});*/
	
	// Screenshots
	$('#big-photo').cycle({ 
	    fx:    'fade',
	    timeout: 0,
	    speed: 250,
	    pager:  '#nav-thumbnails', 
	    pagerEvent: 'mouseover',
    	pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#nav-thumbnails li:eq(' + idx + ') a'; 
    	} 
	});
	/*var activeid = '';
	i = 1;
	$('.thumbnail img').each( function (e) { 
		if(i==1) activeid = jQuery(this).attr('src');
	
		itemval = jQuery(this).attr('src');
		file = retrieveScreenshot(itemval, 'medium');
		jQuery("<img>").attr("src", file);
		i++;
	});

	$('.thumbnail img').hover( function (e) { 
		curid = jQuery(this).attr("src");
		if(activeid==curid) return false;
		activeid = curid;

		itemval = jQuery(this).attr('src');
		mediumimage = retrieveScreenshot(itemval, 'medium');
		popupimage = retrieveScreenshot(itemval, 'popup');
		
		if(file){
			jQuery(".screenshot a.photobox").attr('href', popupimage);
			jQuery("#big-image").fadeOut(400,function() {
			jQuery(this).attr('src', mediumimage).fadeIn(600);});
		}
	});*/
	
	jQuery("a.photobox").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0,
		'overlayShow': true,
		'overlayOpacity': 0.7
	});    
	jQuery("a.youtube").fancybox({
		'zoomSpeedIn':	100, 
		'zoomSpeedOut':	100,
		'frameWidth': 425,
		'frameHeight': 344,
		'overlayShow': true,
		'overlayOpacity': 0.6
	});    
	
});

function switchLanguage(lang) {
    u = location.href.split('/');
    u[5] = lang;
    location.href = u.join('/');
}
