$(function() {
	$.ajax({
		url: $.httpbase()+'base/dynamic/',
		type: 'POST',
		data: {location: document.location.href},
		dataType: 'json',
		success: function(r) {		
			
            if (r.nomobile == false && typeof DetectTierTablet == 'function') {
                if (DetectTierTablet() || DetectAndroidPhone() && Math.min(window.outerWidth, window.outerHeight) >= 600) {
                        document.location.href = 'http://tablet.omoda.nl';
                } else if (DetectTierIphone() || DetectTierRichCss() || DetectTierOtherPhones()) {
                        document.location.href = 'http://omoda.mobi';
                }       
            }

			$('#shoppingbag a').append(r.order_aantal);
			if (r.aantal > 0) {
				$('#shoppingbag').addClass('active');
			}
			
			$('#blok_login').html(r.blok_login);
			$('.laatst_bekeken').replaceWith(r.blok_laatst_bekeken);
			
			//SUPPORT
			var values = new Array();
			var inputs = $("#blok_login :input");
		
			inputs.each(function(i,e) {
				values[i] = e.value;
				if($(e).hasClass("clear")) {
					$(e).focus(function() {			
						if(e.value == values[i]) {				
							e.value = '';
						}
					});
					$(e).blur(function() {
						if(e.value == '') {
							e.value = values[i];
						}
					});
				} else if($(e).hasClass("password")) {
					$(e).focus(function() {			
						if(e.value == values[i]) {				
							e.value = '';
							e.type = 'password';
						}		
					});
					$(e).blur(function() {
						if(e.value == '') {
							e.value = values[i];
							e.type = 'text';
						}				
					});
				}
			});
			
			$('#login_wachtwoord').hide();
			$('#login_tekst').focus( function(){
				if (this.value.toLowerCase() == 'wachtwoord' || this.value.toLowerCase() == 'passwort'){
					$('#login_wachtwoord').show();
					$('#login_wachtwoord').focus();
					$('#login_tekst').hide();
				}
			});
			
			$('#login_wachtwoord').blur( function(){
				if ((this).value == ''){
					$('#login_tekst').show();
					$('#login_wachtwoord').hide();
				}
			});	
			
			$('#blok_login .clear').each( function() {
				value = $(this).val();		
				$(this).focus( function() {
					if($(this).val() == value) {
						$(this).attr("value","");
					}
				});
				$(this).blur( function() {
					if($(this).val() == "") {
						$(this).attr("value",value);
					}
				});
			});
		}
	});
});

