$(function() {
		   
		//Change country selector
		$('li#change_country').click(function(){
		  if(!$('#country_selector').is(':visible')) {
				$('#country_selector').show();
		  } else {
			$('#country_selector').hide();
		  }
		});
		
		$('body').click(function(event){
			if(!$(event.target).parent().is('li#change_country')){
				$('#country_selector').hide();	
			}
		});
		
});

$(function(){
	window.productSlider = {
		init : function(){
			if($('#productSlider').length > 0){
				
				var _width = 0;
				var _margin = 0;
				var _fullWidth  = 0;
				$('div.productSliderProduct').each(function(i, element){
					_width = $(element).outerWidth(true);
					_fullWidth += _width;
					$('#productSliderLoadingIndicator').css({'opacity':'0.7'});
					$(element).find('a').bind('click', function(event){
						event.stopPropagation();
						event.preventDefault();
						var _href = $(this).attr('href').split('?');
						var _qString = _href[1].split('=');
						var _ID = _qString[1];
						var _url = _href[0] + '?ajax=1 #' + _ID;
						productSlider.getContent(_url, _ID);
					});
					
				});
				if($.browser.msie && $.browser.version <=6) {
					_fullWidth = _fullWidth + 30;
				}
				$('div.productSliderProductsSlide').width(_fullWidth);
				$('.jscroll-pane').jScrollPane({
					horizontalGutter:20,
					mouseWheelSpeed:5,
					verticalDragMinHeight: 15,
					verticalDragMaxHeight: 15,
					horizontalDragMinWidth: 130,
					horizontalDragMaxWidth: 130
				});
			}
		},
		getContent : function(_url, id){
			$('#productSliderLoadingIndicator').fadeIn('fast');
			$('div#productSliderLoadingContainer div.productSliderBannerItem').fadeOut('slow', function(){
				$('div#productSliderLoadingContainer').load(_url, function(responseText, textStatus, XMLHttpRequest){
					$('#productSliderLoadingIndicator').fadeOut('fast');
					$('div#productSliderLoadingContainer div.productSliderBannerItem').fadeIn('slow');
					
					
					// If IE 6 change Headline Style:
					if($.browser.msie && $.browser.version <=6) {
						var _url = $('#productSliderLoadingContainer .headline h1').css('background-image');
						_url = _url.split('"');
						_url = _url[1];
						$('#productSliderLoadingContainer .headline h1').css({
							'background':'none',
							'filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=1,src='" + _url + "', sizingMethod='image')"
						});
						//alert($('#productSliderLoadingContainer .headline h1')[0].style.filter);
					}
					
				});
			});
		}
	};
});
