$(window).load(function(){

	languages();
	$("#theThings").at_intervals(banners, { delay: 2000, name: "banners" });
	changeProps();
	
	menu();
	
	buyBtn();
	
	sameas();
	
});

function sameas(){
	$('#sameas').change(function(){
		
		if($(this).attr("checked")){
			$('#reghideme').hide();
		} else {
			$('#reghideme').show();
		}
	});
}

function buyBtn(){
	$('.amountTable').change(function(){
		//alert($(this).attr('data-id'));
		var btnn = $('#btnn'+$(this).attr('data-id'));
		btnn.attr('href', btnn.attr('href') + '&amount=' + $(this).val());
	});
}

function menu(){
	$('.topmenu > ul > li').mouseover(function(l){
		if($(this).children('ul')){
			$(this).addClass('hovered');
		}
	});
	
	$('.topmenu ul > li').mouseout(function(l){
		if($(this).children('ul')){
			$(this).removeClass('hovered');
		}
	});
}

function changeProps(){
	$('#prodRows').change(function(){
		window.location = $('#theprop').val() + $(this).val();
	});
}

function languages(){
	$('#dropdown').click(function(){
		
		if (!$('#lng_dropdown').hasClass('opened')){
			$('#lng_dropdown').slideDown();
			$('#lng_dropdown').addClass('opened');
		} else { 
			$('#lng_dropdown').slideUp();
			$('#lng_dropdown').removeClass('opened');
		}
		
	});
}

function banners(){
	if(this.count || this.count == 0){
		this.count++;
	} else {
		this.count = 0;
	}
	
	var all = $("#theThings .theThing").size();
	var sel = $("#theThings .selected")[0];
	
	if(this.count == all){
		this.count = 0;
	}
	
	var next = $("#theThings .theThing")[this.count];
	
	$(sel).removeClass('selected');
	$(next).addClass('selected');
	
	$(sel).fadeOut();
	$(next).fadeIn();
}
