function mobiele_versie() {
     jQuery.post(document.location.href+"",{is_mobile_browser:true},function(data) {
	 	if (data == "1") {
			document.location.reload(); 
		}				
	})
}

function normale_versie() {
     jQuery.post(document.location.href+"",{reset_mobile_browser:true},function(data) {
	 	if (data == "1") {
			document.location.reload(); 
		}				
	})
}

jQuery(function() {
	
	
	jQuery('a.prev,a.next').live('click',function() {
		par = jQuery(this).parent()
		jQuery.post(jQuery(this).attr('href'),{ajaxbrowse:true},function(data) {
			par.html(data)
		});
		return false;
	})
	
	
	var sl = jQuery(".slides");
	if (sl.length != 0) {
            
		var slidetimeout = sl.parent().find(".timeout").val();		
		sl.cycle({ 
	            fx:     'scrollHorz', 
	            prev:   '.prevslide', 
	            next:   '.nextslide', 
	            timeout: slidetimeout 
	        });
	}
        
        //graphs
        var gr = $('.graphslides');
        gr.css('position', 'relative');
        $('.gotograph button').css('position', 'relative');
        $('.gotograph button').css('z-index', '5');
        
        if (gr.length != 0) {
            gr.children().css("position", "absolute");
            gr.children().css("left", "0");
            gr.children().css("top", "0");
            gr.children().css("z-index", "1");
            gr.children().first().css("z-index", "2");
           
            
            $('.gotograph button').click(function(){
                var igoto = parseInt($(this).val())+1;
                
                jQuery(".gotograph button").removeClass('active');	
		$(this).addClass('active');
                
                gr.children().css("z-index", "1");
                gr.children("div::nth-child("+igoto+")").css("z-index", "2");
            });
        }
        
	
	jQuery(".goto button").click(function() {
		var newval = $(this).val();
		
		
		jQuery(".goto button").removeClass('active');	
		$(this).addClass('active');
				
		var sl = jQuery(".slides"); 					
		sl.cycle(parseInt(newval));
		return false;			
	});
	
	
	if (jQuery("div.mobile_detect").length > 0) {
		
		var ua = navigator.userAgent.toLowerCase();
		var isAndroid = (ua.indexOf("android") != -1);
		var isIphone = (ua.indexOf('iphone') != -1);
		var isWindowsPhone = (ua.indexOf("windows phone") != -1);
		
		//auto redirect bij mobiel     
		if (jQuery("div.mobile_detect").css("display") == 'block' || isAndroid || isIphone || isWindowsPhone) {
			mobiele_versie();						
		}
	}
	
	jQuery("a.reset_mobile_browser").click(function() {
	 	normale_versie();
		return false;
	})
	
	jQuery("a.is_mobile_browser").click(function() {
		mobiele_versie();
	 	return false;
	})
	
		
})
