function doLog(s) {
    /*try {
        console.log(s);
    } catch (e) { }
    */
}

function fixMinHeight() {
    var min_height = 460;
    $obj = $('div.siteContainer div.scContent');
    var h = $obj.height();
    
    if ($obj.height() < min_height) $obj.css('height', min_height+'px');
    
}

var vitablendSwf = {
     
    insertFooter: function(baseURL, altContentId, w, h) {
        var headSWF = baseURL + 'footer-animatie.swf';
        var flashvars = { };
        var params = {
            menu: "false",
            scale: "noScale",
            allowFullscreen: "false",
            allowScriptAccess: "always",
            bgcolor: "#E8EFFB",
            //align: 'tl',
            wmode: "transparent"
        };
        var attributes = {
            id: altContentId + "FooterSWF"
        };
        swfobject.embedSWF(headSWF, altContentId, w, h, "9.0.0", baseURL + "expressInstall.swf", flashvars, params, attributes);
    },



    insertTopMenu: function(baseURL, altContentId, w, h, flashvars) {
    
        var headSWF = baseURL + 'VitablendTopMenu.swf';
        if (!flashvars) flashvars = {};
        var params = {
            menu: "false",
            scale: "noScale",
            /*allowFullscreen: "false",*/
            allowScriptAccess: "always",
            bgcolor: "#FFFFFF",
            wmode: "transparent",/*windowless*/
            align: 'tl'
        };
        var attributes = {
            id: altContentId + "TopMnuSWF"
        };
        swfobject.embedSWF(headSWF, altContentId, w, h, "9.0.0", baseURL + "expressInstall.swf", flashvars, params, attributes);
}
};

/** START JiFR Functions */


var AllFonts = {};
function initJifr(fontBase, swf, cssUrl) {
    var $ = jQuery,
      cfg = {
          wmode: 'transparent', /* windowless */
          resizeMode: 'both',
          rollbackOnError: true,
          condenseWhitespace: true,
          autoGenerateCSS: true,
          fontSize: 12,
          color: '#000000',
          bgColor: '#FFFFFF',
          detectColors: false,
          swf: swf
      };
    if (cssUrl) cfg.cssURL = cssUrl;
    $.jifr.init(cfg);

    //setup font array for easy usage
    //fontBase
    AllFonts = {
        Arial:
			{
			    //url: the url to the swf
			    url: fontBase + 'Arial.swf',
			    //name: the font-name that will be used as a default
			    name: 'Arial',
			    //fonts, an array with classes and/or fields that will be loaded as fonts from the swf 
			    fonts: [{ className: 'JIFRFont', fields: ['_Font']}]
			}
        , ArialBold:
        { url: fontBase + 'ArialBold.swf', name: 'Arial',
            fonts: [{ className: 'JIFRFont', fields: ['_FontBold']}]
        },
        ArialItalic:
        { url: fontBase + 'ArialItalic.swf', name: 'Arial',
            fonts: [{ className: 'JIFRFont', fields: ['_Font']}]
        },
        MyriadProBlackIt : {
            url : fontBase + 'MyriadPro-BlackIt.swf', name : 'Myriad Pro Black',
            fonts : [{className: 'JIFRFont', fields: ['_Font']}] 
        } ,
        MyriadProBlack : {
            url : fontBase + 'MyriadPro-Black.swf', name : 'Myriad Pro Black',
            fonts : [{className: 'JIFRFont', fields: ['_Font']}] 
        } ,
         MyriadProRegular : {
            url : fontBase + 'MyriadPro-Regular.swf', name : 'Myriad Pro',
            fonts : [{className: 'JIFRFont', fields: ['_Font']}] 
        } ,
         MyriadProIt : {
            url : fontBase + 'MyriadPro-It.swf', name : 'Myriad Pro',
            fonts : [{className: 'JIFRFont', fields: ['_Font']}] 
        } 
        
    };
}

function toggleJifr() {
    if(window.vitablendJifrEnabled)
        rollbackJifr();
    else
        doJifr();
}

function rollbackJifr() {
    window.vitablendJifrEnabled = false;
    $.jifr.rollback();
}
function doJifr() {
    window.vitablendJifrEnabled = true;
    var cfg = {
    //wmode : 'transparent',
        logFlash : false,
        wordwrap: true,
        fontSize: 14,
        externalFonts: [
	    	
            //AllFonts.MyriadProBlack, 
            //AllFonts.MyriadProBlackIt,
            //AllFonts.MyriadProRegular, 
            AllFonts.MyriadProIt
    	]
    };

    //$('div.testJifr').jifr(cfg);
    
    
    
    //replace h2
    cfg.fontStyle = "italic";
    cfg.wordwrap = false;
    cfg.multiline = false;
    cfg.fontSize = 28;
    cfg.fontSize = 24;
    cfg.fontSize = 22;
    cfg.resizeMode = 'width';
    $('h2').jifr(cfg);


    cfg.fontStyle = "italic";
    cfg.fontSize = 33;
    cfg.resizeMode = 'both';
    
    $('h1').jifr(cfg);
    
}
/** END JiFR Functions */



/** Search */



var VitablendSearch = (function($) {
    /** PRIVATE FUNCTIONS #1 */


    /** CONSTRUCTOR */
    return function(txtId, lnkId, searchUrl) {
        /** PRIVATE FUNCTIONS #2 */
        var inst = {
            txtId: false,
            lnkId: false,
            initialTextValue: '',
            searchUrl: false,
            init: function(txtId, lnkId, searchUrl) {
                this.txtId = txtId;
                this.lnkId = lnkId;
                this.searchUrl = searchUrl;
                this.initialTextValue = $('#' + this.txtId).get(0).value;
                doLog('init textfield ID: ' + txtId);
                doLog('init textfield with: ' + this.initialTextValue);
                this.initLink();
                this.initTextField();
            },
            setInitialTextValue: function(txtValue) {
                this.initialTextValue = txtValue;
            },
            initLink: function() {
                var that = this;
                /*
                $('#' + that.lnkId + ' a')
                .data('clientsideonly', true)
                .click(function(e) {
                that.doSearch();
                return false;
                });*/
                $('#' + that.lnkId)
					.css('cursor', 'pointer')
                    .data('clientsideonly', true)
                    .click(function(e) {
                        that.doSearch();
                        return false;
                    });
            },
            doSearch: function(searchTerm) {
                doLog('do search 1');
                if (typeof (searchTerm) == 'undefined' || searchTerm == '' || !searchTerm) {
                    doLog('do search 2 ' + this.txtId);
                    searchTerm = $('#' + this.txtId).get(0).value;
                }
                doLog('do search 3 ' + searchTerm);
                if (searchTerm != '' && searchTerm != this.initialTextValue) {
                    //do search...
                    var url = this.searchUrl + '?q=' + escape(searchTerm);
                    document.location.href = url;
                }
            },

            initTextField: function() {
                var that = this;
                var txtObj = $('#' + this.txtId).get(0);
                if (!txtObj) return;


                $('#' + this.txtId)
                    .addClass('searchInitial')
                    .blur(function(e) {
                        if (this.value == '') {
                            this.value = that.initialTextValue;
                            $(this).addClass('searchInitial');
                        }
                    })
                    .focus(function(e) {
                        if (this.value == that.initialTextValue)
                            this.value = '';
                        $(this).removeClass('searchInitial');
                        //else alert(this.value + "\n\n" + that.initialTextValue);
                    })
                    .keydown(function(e) {
                        if (e.charCode) {
                            if (e.charCode == 13) {
                                that.doSearch();
                                return false;
                            }
                        } else if (e.keyCode) {
                            if (e.keyCode == 13) {
                                that.doSearch();
                                return false;
                            }
                        }
                        return true;
                });
            }
        };

        inst.init(txtId, lnkId, searchUrl);

        /** PUBLIC FUNCTIONS */
        this.doSearch = function() {
            inst.doSearch.apply(inst, arguments);
        };
        this.setInitialTextValue = function() {
            inst.setInitialTextValue.apply(inst, arguments);
        };
    };
})(jQuery);

/** end search */



var VitablendWatermark = (function($) {
    /** PRIVATE FUNCTIONS #1 */


    /** CONSTRUCTOR */
return function(txtId, initialText) {
        /** PRIVATE FUNCTIONS #2 */
        var inst = {
            txtId: false,
            initialTextValue: '',
            init: function(txtId, initialText) {
                this.txtId = txtId;
                if (initialText && initialText != '')
                    this.initialTextValue = initialText;
                else
                    this.initialTextValue = $('#' + this.txtId).get(0).value;
                this.initTextField();
            },
            setInitialTextValue: function(txtValue) {
                this.initialTextValue = txtValue;
            },

            initTextField: function() {
                var that = this;
                var $txtObj = $('#' + this.txtId);
                var txtObj = $txtObj.get(0);
                if (!txtObj) return;


                $txtObj
                //.addClass('searchInitial')
                    .blur(function(e) {
                        if (this.value == '') {
                            this.value = that.initialTextValue;
                            $(this).addClass('searchInitial');
                        }
                    })
                    .focus(function(e) {
                        if (this.value == that.initialTextValue)
                            this.value = '';
                        $(this).removeClass('searchInitial');
                        //else alert(this.value + "\n\n" + that.initialTextValue);
                    });
                    
                    if (txtObj.value == this.initialTextValue) {
                        $txtObj.addClass('searchInitial');
                    }   
            }
        };

        inst.init(txtId, initialText);

        /** PUBLIC FUNCTIONS */

        this.setInitialTextValue = function() {
            inst.setInitialTextValue.apply(inst, arguments);
        };
    };
})(jQuery);

var currentlyOpenFaq = false;
function showFaq(id) {
    var duration = 100;
    var closeDuration = 0;
    var fqDiv = $('#' + id);
    if (fqDiv.length == 0) return;
    if (currentlyOpenFaq) {
        $('#' + currentlyOpenFaq + ' div.faqText').hide(closeDuration);
        $('#' + currentlyOpenFaq).removeClass('faqVisible');
        currentlyOpenFaq = false;
    }
    currentlyOpenFaq = id;
    fqDiv.addClass('faqVisible');
    $('#' + id + ' div.faqText').show(duration);

}


function toggleSitemap() {
    $('.sccFooterLinks').toggle("fast", function callback() {
        $.scrollTo('max', '500');
    }
);
}

$(document).ready(function() {
    $('.home_bioLink img').hover(function() {
        $(this).attr('src', '../img/v2/homebutton-light.png');
    }, function() {
        $(this).attr('src', '../img/v2/homebutton_dark.png');
    });
    $('.bioDiselButton img').hover(function() {
        $(this).attr('src', '../img/v2/protection-button-blue-and-white-hover.png');
    }, function() {
        $(this).attr('src', '../img/v2/protection-button-blue-and-white.png');
    });
});