var b_img = new Array();
//b_img[0] = "bg.jpg";
b_img[1] = "bg1.jpg";
b_img[2] = "bg2.jpg";
b_img[3] = "bg3.jpg";
b_img[4] = "bg4.jpg";
var bgpad = "/wp-content/themes/venb/images/";


function setNewBg(i){
    var img = bgpad + b_img[i];
    //load new background image in bottom div
    jQuery('#bg_sw_a').css('background', 'url(' + img + ') no-repeat center top');
    setTimeout('fadeOut(' + i + ')', 1000);
}
function fadeOut(i){
    //fadeout topmost div
    jQuery("#bg_sw_b").animate({opacity: 0}, 1000);
    setTimeout('switchBg(' + i + ')', 1050);
}
function switchBg(i) {
    var img = b_img[i];
    //set the background of the topmost div equal to the bottom div, and fadein the topmost div
    var curr = jQuery('#bg_sw_a').css('background');
    jQuery('#bg_sw_b').css('background', curr);
    jQuery('#bg_sw_b').animate({opacity: 1}, 100); //quickly, because pic beneath it is the same
    if (i >= 4) i = 1;
    else i += 1;
    //rinse and repeat with next image
    setTimeout('setNewBg(' + i + ')', 12000);
}

function openDialog(url, title, height, width){
	if (height == 0)
		height = document.documentElement.clientHeight - 20;
	if (width == 0)
		width = document.documentElement.clientWidth - 20;
	jQuery("#dialogIframe").attr("src", url);
	jQuery("#dialog").dialog("option", "height", height);
	jQuery("#dialog").dialog("option", "width", width);
	jQuery("#dialog").dialog("option", "title", title);
	jQuery("#dialog").dialog("open");
}+

jQuery(document).ready(function(){
    jQuery("#name").inputLabel();
    jQuery("#email").inputLabel();
    jQuery("#telefoonnummer").inputLabel();
    jQuery("#bedrijfsnaam").inputLabel();
    jQuery("#message").inputLabel();


    jQuery("#_name").inputLabel();
    jQuery("#_mail").inputLabel();
    jQuery("#_phone").inputLabel();
 
	jQuery("#dialog").dialog({
                    autoOpen: false,
                    modal: true,
                    draggable: false,
                    resizable: false,
                    close : function(){
                        jQuery("#dialogIframe").attr("src", "");
                    }
                });
        jQuery("#nieuws_block,#part_block,#fs_block").live('click', function(e) {  
                //e.preventDefault();  
                var target = e ? e.target : window.event.srcElement; 
                if (target.nodeName.toLowerCase() === 'h2') { // is a title clicked? 
                        var parent = '#' + jQuery(target).parent().parent().attr('id');              //where are we? (what is the containing id?) 
                        // 'close' everything in the containing div 
                        jQuery(parent + ' .openclose h2').removeClass('special'); 
                        jQuery(parent + ' .openclose p').animate({ "height": "hide", "opacity": "hide" }); 
                        // 'open' clicked item 
                        jQuery(target).toggleClass('special');                                                                                       // change the color of the title 
                        jQuery(target).next().animate({ "height": "toggle", "opacity": "toggle" });  // slide/fade the 'next' item after the h2 
                } else if (target.nodeName.toLowerCase() === 'a') { // a link is clicked 
                        window.location.href = jQuery(target).attr('href'); 
                } 
                return false; 
        }); 
    //start fading the background images
    setNewBg(1);
        jQuery('#logo').click(function(e) {
                 document.location.href="http://www.verbeekenbornebroek.nl";
                 return false;
        });

	jQuery('#topslide_btn').click(function(e) {
 	e.preventDefault();
		jQuery("#topslider_content").animate({ "height": "toggle", "opacity": "toggle" });
		return false;
	});
	
	jQuery(".switch_item img").tooltip('#tooltip');

	function load_data(){
		var data		= new Object();
		data.branche	= jQuery("#branche_id").val();
		data.categorie	= jQuery("#product_list option:selected").val();
		data.soort		= jQuery("#soort_list option:selected").val();
		data.merk		= jQuery("#merk_list option:selected").val();
		
		jQuery.ajax({
			type: "POST",
			data: data,
			url: "/wp-content/themes/venb/product_json.php",
			async: false,
			dataType: 'json',
			success: function(msg) {
				jQuery('#selectfields').html(msg.boxen);
				jQuery('#contentContainer #title').html(msg.title);
				jQuery('#contentContainer #intro').html(msg.description);
				jQuery('#fcontent').html(msg.content);
					jQuery('#selectfields select').livequery('change', function(){
						load_data();
					});
			}
		});
	}

    jQuery("button.visit_site").click(function(){
        document.location.href="http://www.fluidsupport.nl";
        return false;
    });

        jQuery("#info_fluidsupport.ajaxSubmit").submit(function(event) {
                event.preventDefault();
                var data                = new Object();

                data.name    = jQuery("#_name").val();
                data.mail    = jQuery("#_mail").val();
                data.phone   = jQuery("#_phone").val();
                data.type    = "contactaanvraag";
                jQuery("#info_fluidsupport .ajaxSubmitButton").attr("disabled", "disabled");
                jQuery("#info_fluidsupport .ajaxSubmitButton").html("Bezig met verzenden");
                jQuery.ajax({
                        type: "POST",
                        data: data,
                        url: "/wp-content/themes/venb/mail_json.php",
                        async: false,
                        dataType: 'json',
                        success: function(msg) {
                                if(msg.success == "0"){
                                        jQuery("#info_fluidsupport .ajaxSubmitButton").removeAttr("disabled");
                                        jQuery("#info_fluidsupport .ajaxSubmitButton").html("Alle velden zijn verplicht");
                                } else {

                                        jQuery("#info_fluidsupport .ajaxSubmitButton").html("Verzonden !");
                                }
                        }
                });

        });
	
        jQuery("#contactForm.ajaxSubmit").submit(function(event) {
                event.preventDefault();
                var data                = new Object();

                data.name    = jQuery("#name").val();
                data.mail    = jQuery("#email").val();
                data.phone   = jQuery("#telefoonnummer").val();
		data.company = jQuery("#bedrijfsnaam").val();
		data.message = jQuery("#message").val();
                data.type    = "infoaanvraag";
                jQuery("#frm_btns2 .ajaxSubmitButton").attr("disabled", "disabled");
                jQuery("#frm_btns2 .ajaxSubmitButton").html("Bezig met verzenden");
                jQuery.ajax({
                        type: "POST",
                        data: data,
                        url: "/wp-content/themes/venb/mail_json.php",
                        async: false,
                        dataType: 'json',
                        success: function(msg) {
                                if(msg.success == "0"){
                                        jQuery("#frm_btns2 .ajaxSubmitButton").removeAttr("disabled");
                                        jQuery("#frm_btns2 .ajaxSubmitButton").html("Alle velden zijn verplicht");
                                } else {

                                        jQuery("#frm_btns2 .ajaxSubmitButton").html("Verzonden !");
                                }
                        }
                });

        });
	
	jQuery('#selectfields select').livequery('change', function(){
		load_data();
	});
	
	jQuery('.prod_select').livequery ('click', function(){
		var data = new Object();
		data.action = "get";
		data.get_product = jQuery(this).attr('id');
		jQuery.ajax({
			type: "GET",
			data: data,
			url: "/wp-content/themes/venb/product_json.php",
			async: true,
			dataType: 'json',
			success: function(msg) {
				//jQuery('#selectfields').html(msg.boxen);
				jQuery('#contentContainer #title').html(msg.title);
				jQuery('#contentContainer #intro').html(msg.description);
				jQuery('#fcontent').html(msg.content);
			}
		});
	});


})

