$ (document).ready (function () {

        
        // doelgroepen terug buton - set margin-top
        
        var block_left = $ ('.subpage .description').height () - 40;
        var block_right = $ ('.referenties .description').height () - 40;
        
        if (block_left > block_right)
        {
                if (block_left > 0)
                        $ ('.image .terug').css ('margin-top', block_left + 'px');
                else
                        $ ('.image .terug').css ('margin-top', 0 + 'px');
        }
        else
        {
                if (block_right > 0)
                        $ ('.image .terug').css ('margin-top', block_right + 'px');
                else
                        $ ('.image .terug').css ('margin-top', 0 + 'px');
        } 

        // set height of left right
        var height_t = setTimeout ("checkHeight ()", 200);   
        
        // show selected news item
        var item_t = setTimeout ("itemselected ()", 400);
        
        // center submenu
        var submenu_t = setTimeout ("center_submenu ()", 180);  
        
        
        // links title
        
        $ ("body").append ("<div id='ToolTipDiv'></div>");
        
        $ (".block_calculeer_0 a[rel], .block_calculeer_1 a[rel]").each (function () 
        {
                $ (this).hover (function (e) 
                {   
                        $ (this).mousemove (function (e) 
                        {     
                                var tipY = e.pageY + 3;
                                var tipX = e.pageX + 16;   
                                $ ("#ToolTipDiv").css ({'top': tipY, 'left': tipX});
                        });
                        $ ("#ToolTipDiv").html ($ (this).attr ('rel')).stop (true,true).fadeIn ("fast");
                        $ (this).removeAttr ('rel');
                        
                }, function () 
                {
                        $ ("#ToolTipDiv").stop (true,true).fadeOut ("fast");
                        $ (this).attr ('rel', $ ("#ToolTipDiv").html ());
                });
        });
        
});

var numb = '0123456789';

function isValid (parm,val) 
{
        
        if (parm == "") return true;
        
        for (i=0; i<parm.length; i++) 
        {
                if (val.indexOf (parm.charAt (i),0) == -1)
                { 
                        return false;
                }
        }
        
        return true;
}

function isNumber (parm) { return isValid (parm,numb); }

function checkForm () 
{
        var branduren_per_dag     = $ ('#branduren_per_dag').val ();
        var aantal_dagen_per_jaar = $ ('#aantal_dagen_per_jaar').val ();
        var aantal_armaturen      = $ ('#aantal_armaturen').val ();
        var aantal_lampen         = $ ('#aantal_lampen').val ();
        var breturn               = true;
        
        $ ('#branduren_per_dag').removeClass ('error');
        $ ('#aantal_dagen_per_jaar').removeClass ('error');
        $ ('#aantal_armaturen').removeClass ('error');
        $ ('#aantal_lampen').removeClass ('error');
        
        if (isNumber (branduren_per_dag) == false || branduren_per_dag == '' || (branduren_per_dag > 24 || branduren_per_dag <= 0))
        {
                $ ('#branduren_per_dag').addClass ('error');       
                
                breturn = false;
        }
        
        if (isNumber (aantal_dagen_per_jaar) == false || aantal_dagen_per_jaar == '' || (aantal_dagen_per_jaar > 366 || aantal_dagen_per_jaar <= 0))
        {
                $ ('#aantal_dagen_per_jaar').addClass ('error');       
                
                breturn = false;
        }
        
        if (isNumber (aantal_armaturen) == false || aantal_armaturen == '' || aantal_armaturen <= 0)
        {
                $ ('#aantal_armaturen').addClass ('error');       
                
                breturn = false;
        }
        
        if (isNumber (aantal_lampen) == false || aantal_lampen == '' || aantal_lampen <= 0)
        {
                $ ('#aantal_lampen').addClass ('error');       
                
                breturn = false;
        }
        
        return breturn;
}

function center_submenu ()
{
        var width = 0;
        
        $ ('nav ul li').each (function (){
                width = width + $ (this).width ();
                return (!$ (this).hasClass ('selected'));
        });
        
        var left = 960 - $ ('nav ul').width () + width - $ ('.submenu ul').width () / 2 - $ ('nav .selected').width () / 2;
        
        if (960 - $ ('.submenu ul').width () < left)
        {
                $ ('.submenu ul').css ('float', 'right');
        }
        else
        {
                $ ('.submenu ul').css ('margin-left', 960 - $ ('nav ul').width () + width - $ ('.submenu ul').width () / 2 - $ ('nav .selected').width () / 2 + 'px'); 
        }
}


function itemselected ()
{                 
        $ ('.show_item').slideDown ("slow"); 
}

// news animation

$ (function () 
{
        $ ('ul li a.title').click (function () 
        {             
                // Check for other opened summaries.
                if ($ (this).hasClass ('selected') == false)
                {
                        $ ('ul li a.selected').next ().animate ({height: 'toggle'}, 'slow', 'linear');
                        $ ('ul li a.selected').removeClass ('selected');
                }

                $ (this).next ().animate ({height: 'toggle'}, 'slow', 'linear');
                $ (this).toggleClass ('selected');
        });
        
        // products animation
        
        $ ('.category').click (function () 
        {
                // Check for other opened summaries.
                if ($ (this).children ('a').hasClass ('selected') == false)
                {
                        $ ('.category a.selected').parent ().next ().animate ({height: 'toggle'}, 'slow', 'linear');
                        $ ('.category a.selected').removeClass ('selected');
                }
                
                // The current summary gets toggled, no need to check that.
                $ (this).next ().animate ({height: 'toggle'}, 'slow', 'linear');      
                $ (this).children ('a').toggleClass ('selected');  
        });
});





function checkHeight () 
{
        var leftBlock = $ ('.left-block').height ();
        var rightBlock = $ ('.right-block').height ();
        //alert ('a');
        if (leftBlock > rightBlock)
        {
                $ ('.right-block').css ('height', leftBlock + 'px');
        }
        else
        {
                $ ('.left-block').css ('height', rightBlock + 'px');   

        }
}

function correctPNG () 
{
        var arVersion = navigator.appVersion.split ("MSIE")
        var version = parseFloat (arVersion[1])
        if ((version >= 5.5) && (document.body.filters)) 
        {
                for (var i=0; i<document.images.length; i++)
                {
                        var img = document.images[i]
                        var imgName = img.src.toUpperCase ()
                        
                        if (imgName.substring (imgName.length-3, imgName.length) == "PNG")
                        {
                                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                                var imgStyle = "display:inline-block;" + img.style.cssText 
                               
                                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                                
                                var strNewHTML = "<span " + imgID + imgClass + imgTitle
                                + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                                + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                                + " (src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
                                img.outerHTML = strNewHTML
                                i = i-1
                        }
                }
        }    
}

function onloadFunc ()
{
        correctPNG ();
}

window.onload = onloadFunc;
