var showLocation;

$(function() {
	$("#city_selector").jqDropDown({
		optionChanged: goArtcom,
		// @temp: chris: 2011-10-14: settings.temporaryBottomFlag to jest proteza, w menu rozwijanyum miast bottom_bkg jest potrzebne a w innych nie.
		temporaryBottomFlag: true
//		defaultOption: $("select").find('option:selected').text()
	});
	$(".slider").rotator({
		tranSpeed : 1800,
		delay   : 7000,
		auto    : true,
		loop    : true
	});
	
	$('.menu_tabs li a').mouseenter(function() {
        $(this).parent().addClass('menu_list_hover');
    }).mouseleave(function() {
        $(this).parent().removeClass('menu_list_hover');
    });
	$('.menu_tabs li a').click(function() {
		$(this).parent().parent().find('.active').removeClass('active');
    $(this).parent().addClass('active');
		if (typeof getProducts === 'function') {
			getProducts($(this).attr('id').substring(9));
		}
		else {
			getPromotion($(this).attr('id').substring(9));
		}
    });
    
	$('.recipes_tabs li a').mouseenter(function() {
        $(this).parent().addClass('menu_list_hover');
    }).mouseleave(function() {
        $(this).parent().removeClass('menu_list_hover');
    });    
    $('.recipes_tabs li a').click(function() {
		$(this).parent().parent().find('.active').removeClass('active');
    $(this).parent().addClass('active');
		getRecipe($(this).attr('id').substring(7));
    });


	$(".menu_tabs").tabs(".column_right > .tab_content");
	$(".recipes_tabs").tabs(".column_right > .tab_content");
	var scrl = $(".scrollable").scrollable({disabledClass: 'arrow_disabled'}).data("scrollable");
  if (scrl && scrl.getSize() > 1) {
		$('#arrow_right').removeClass('arrow_disabled');
	}

	
	var prefix, city,
			city_name = $('#city_name'),
			your_city_name = $('#your_city_name'),
			your_city_text = $('#your_city_text'),
			form_city_selector = $('#form_city_selector'),
			city_selector = $('#city_selector');


	if (city_selector.length) {
		//strona zawiera selecta miejscowości
		prefix = $('#prefix').val();
		if (city_name.length) {
			//strona lokalizacji sklepów
			loadCity();
		}
	}

	function goArtcom(el) {
		if (city_name.length) {
			//strona lokalizacji sklepów
			loadCity();
		}
		else if (city_selector.length) {
			//strona zawiera selecta miejscowości
			form_city_selector.submit();
		}
	}

	function loadCity() {
		city = city_selector.val();
		city_name.html(city);
		your_city_name.html(city);
		your_city_text.show();
		$('#city_stores').empty().html('<img style="margin: 100px 0 0 150px" src="/images/ajax-loader.gif" />');
		$('#city_stores').load(prefix + "ajax/storesGet", {city: city});
	}

	showLocation = function (store_nr, shop_location) {
		$('#city_stores a').removeClass('active');
		$('#location_'+store_nr).addClass('active');
		loadMap(shop_location, store_nr);
	};
});


