KARE.Start = function() {
		
	function setup() {
		
		//$("#selectCountry").selectbox();
		//$("#selectCity").selectbox();
		//$("#selectStore").selectbox();
		$("#selectCityContainer").hide();
		$("#selectStoreContainer").hide();
		var count = 0;
		
		$("#selectCountry").change(function(event)
		{
			$("#iconLoading").show();
			if($('#selectCountry').val() == 'au')
			{
				document.location.href = 'http://www.kconcept.com.au/Products.aspx?show=t';
			} else {	
				$.ajax({
					cache: false,
					dataType: 'json',
					type: 'GET',
					//url: '/ajax/?a=getCities&b=' + $('#selectCountry').val() + "&c=" + KARE.Main.getLanguage(),
					url: '/ajax/?a=getCities&b=' + $('#selectCountry').val() + "&c=" + 'en',
					error: function(obj, msg, e){
						//console.error(obj, msg, e);
						alert('error: ' + msg);
					},
					success: function(json){
						$("#iconLoading").hide();
						var resCount = 0;
						var tmpObj = "";
						$.each(json, function(i,tempItem){tmpObj=i;resCount++});
						if($("#selectCountry").val() != '0')
						{
							resetSelect("#selectCity");
							$("#selectCityContainer").show();
							$("#selectStoreContainer").hide();
							$("#selectCity").addOption({'0':'Choose your city'});
							$("#selectCity").addOption(json, false);
							//$("#selectCity").addOption("&nbsp;", "", false);
							sortDropDown("#selectCity");
							updateSelect('#selectCity');
						}
						if(resCount == 1)
						{
							$("#selectCity").selectOptions(tmpObj);
							updateSelect('#selectCity');
							$("#selectCity").change();
						}
					}
				});
			}
		})
		
		$("#selectCity").change(function(event)
		{
			$("#iconLoading").show();
			if($("#selectCity").val() != undefined)
			{
				//console.log(encodeURI($('#selectCity option:selected').text()));
				//console.log(escape($('#selectCity option:selected').text()));
				//console.log($('#selectCity option:selected').text());
				$.ajax({
					cache: false,
					dataType: 'json',
					type: 'GET',
					url: '/ajax/?a=getStores&b=' + encodeURI($('#selectCity option:selected').text()),
					error: function(obj, msg, e){
						//alert('error: ' + msg);
					},
					success: function(json){
						$("#iconLoading").hide();
						var resCount = 0;
						var tmpObj = "";
						$.each(json, function(i,tempItem){tmpObj=i;resCount++});
						if(resCount == 1)
						{
							document.location.href = '/en/shop' + tmpObj + '/home_redirect/';
						}
						else if($("#selectCity").val() != '0')
						{
							resetSelect("#selectStore");
							$("#selectStoreContainer").show();
							$("#selectStore").addOption({'0':'Choose your shop'});
							$("#selectStore").addOption(json, false);
							//$("#selectStore").addOption("&nbsp;", "", false);
							updateSelect('#selectStore');
							console.log('qwer');
						}
					}
				});
			}
		})
		
		$("#selectStore").change(function(event)
		{
			if($("#selectStore").val() != '0')
			{
				//document.location.href = "/" + KARE.Main.getLanguage() + '/' + $("#selectStore").val() + '/home/';
				document.location.href = '/en/' + $("#selectStore").val() + '/home_redirect/';
			}
		})
		
		$("#imprintLoginContainer a").click(function(){
			$("#popupContainer").fadeIn('fast',addSliderAction);
			return false;
		})
		
		$("#popupContainer #closeBut").click(function(){
			$("#popupContainer").fadeOut();
			return false;
		})
		
	}
	
	function addSliderAction()
	{
		$("#sliderX").slider(
  		{
  			slide: function()
  			{
  				var maxScroll = $("#textX")[0].scrollHeight - $("#scrollLayerX")[0].scrollHeight + 20; // + 20 because of padding
  				var percentToAmount = (maxScroll/100)* $("#sliderX").slider("value"); 
  				//$("#textA").animate({scrollTop: percentToAmount}, .01);
  				$("#textX").scrollTop(percentToAmount);
  			},
  			change: function()
  			{
  				var maxScroll = $("#textX")[0].scrollHeight - $("#scrollLayerX")[0].scrollHeight + 20; // + 20 because of padding
  				var percentToAmount = (maxScroll/100)* $("#sliderX").slider("value"); 
  				$("#textX").scrollTop(percentToAmount);
  			}
  		});
  		//:MOUSEWHEEL SUPPORT
  		$("#scrollLayerX").mousewheel(function(event, delta) 
  		{
  			if(isNaN($("#sliderX").slider("value"))) $("#sliderX").slider("moveTo", 0);
  			$("#sliderX").slider("moveTo", $("#sliderX").slider("value") - delta * 8);
		})
	}
	
	function updateSelect(_arg)
	{
		//$(_arg).parents('.jquery-selectbox').unselectbox();
		//$(_arg).selectbox();
	}
	
	function resetSelect(_arg)
	{
		$(_arg).removeOption(/./);
		//$(_arg).parents('.jquery-selectbox').unselectbox();
		//$(_arg).selectbox();
	}
	
	function sortDropDown(selector)
	{
		var $dd = $(selector);
		if ($dd.length > 0) {
		    var selectedVal = $dd.val();
		    var $options = $('option', $dd);
		    var arrVals = [];
		    $options.each(function(){
		        // push each option value and text into an array
		        arrVals.push({
		            val: $(this).val(),
		            text: $(this).text()
		        });
		    });
		    //numeric
		    /*arrVals.sort(function(a, b){
		        return a.val - b.val;
		    });*/
		    //alphabetical
		    arrVals.sort(function(a, b){
			    if(a.val>b.val){
			        return 1;
			    }
			    else if (a.val==b.val){
			        return 0;
			    }
			    else {
			        return -1;
			    }
			});
		    for (var i = 0, l = arrVals.length; i < l; i++) {
		        $($options[i]).val(arrVals[i].val).text(arrVals[i].text);
		    }
		    $dd.val(selectedVal);
		}

	}
	
	function createPlaceSelector(_country)
	{
		/*$("#placeSelector").html("");
		$("#placeSelector").flexbox('/ajax/ajWilken?a=getStores&b='+_country, 
		{	allowInput: false,
			width: 300,
			watermark : 'Choose Country',
			maxVisibleRows: 10,
			paging: false,
			onSelect: function()
			{
				
			}
		});*/
	}
	
	function init() {
		
		$(function(){
			if($("body").hasClass('start'))
			{
				setup();
			}
		});
		
		return this;
	}
	
	return {
		init: init
	}
	
}();

KARE.Start.init();
