﻿jQuery.noConflict();
var timer = 0;
var inMotion = 0;
var offset = 0;
var max_offset = 0;
var timeToSlide = 8000;
jQuery(function($) {

	$('#searchForm, #artnrForm').css({'opacity': '0.2'});
	$('#searchForm, #artnrForm').hover(function() {
		$(this).animate({'opacity': '1'}, '300');
	}, function() {
		$(this).animate({'opacity': '0.2'}, '300');
	});
	if($('.slide').length > 1) {
		offset = $('.slide img:first').width();
		max_offset = ($('.slide img:first').width() * $('.slide').length) - (offset * 2);
		$('.slides').css({'left': '0px', 'height':'285px', 'width': ($('.slide img:first').width() * $('.slide').length) + 'px'});
		setInterval('animateSlider()', timeToSlide);
	}
	if($('.searchResult .item').length > 0) {
		$('.searchResult .item ul li.__search_city').each(function(i) {
			$('#City').append('<option>' + $('span', this).text() + '</option>');
		});
		$('div.searchBox input#zipButton').click(function() {
			var zip = $('#zipCode').val();
			$('.searchResult .item ul li.__search_zip').each(function() {
				var temp = $('span', this).text();
				temp = temp.replace(' ', '');
				if(temp.substr(0, zip.length) == zip) {
					$(this).parent().parent().show();
				}
			});			
		});
		$('div.searchBox input#cityButton').click(function() {
			$('.searchResult .item ul li.__search_city').each(function() {
				if($('span', this).text() == $('#City option:selected').text()) {
					$(this).parent().parent().show();
				}
			});			
		});
	}
});
function animateSlider() {
	var current_offset = jQuery('.slides').css('left').replace('px','').replace('-', '');
	var slideto = Number(current_offset) + Number(offset);
	if(slideto <= max_offset) {
		jQuery('.slides').animate({'left': '-' + slideto + 'px'}, 2000);
	} else {
		jQuery('.slides').animate({'left': '-' + slideto + 'px'}, 2000, function() {
			jQuery(this).css('left','0px');
		});
	}
}
