/*
-------------------------------------------------------------------------------------------------
***** Tientjes.net Javascript *****

Laatste update:    05/03/2011
Copyright:         (c) 2011 Tientjes.net

-------------------------------------------------------------------------------------------------
*/

$(function($) {
        
    $('.menu ul li.sub').hoverIntent(function() {
        var ul = $('ul:first', this); 
        ul.slideDown(250).show();
    }, function() {
        var ul = $('ul:first', this); 
        ul.slideToggle(150);
    })
    
    $('.contact_formulier #naam').focus(function() {
        $(this).addClass('focus');
        if($(this).val() == 'Naam') {
            $(this).val('');
        }
    })
    
    $('.contact_formulier #naam').focusout(function() {
        if($.trim($(this).val()).length == 0) {
            $(this).val('Naam');
            $(this).removeClass('focus');
        } 
    })
    
    $('.contact_formulier #emailadres').focus(function() {
        $(this).addClass('focus');
        if($(this).val() == 'E-mailadres') {
            $(this).val('');
        }
    })
    
    $('.contact_formulier #emailadres').focusout(function() {
        if($.trim($(this).val()).length == 0) {
            $(this).val('E-mailadres');
            $(this).removeClass('focus');
        } 
    })
    
    $('.contact_formulier #telefoon').focus(function() {
        $(this).addClass('focus');
        if($(this).val() == 'Telefoon') {
            $(this).val('');
        }
    })
    
    $('.contact_formulier #telefoon').focusout(function() {
        if($.trim($(this).val()).length == 0) {
            $(this).val('Telefoon');
            $(this).removeClass('focus');
        } 
    })
    
    $('.contact_formulier #onderwerp').focus(function() {
        $(this).addClass('focus');
        if($(this).val() == 'Onderwerp') {
            $(this).val('');
        }
    })
    
    $('.contact_formulier #onderwerp').focusout(function() {
        if($.trim($(this).val()).length == 0) {
            $(this).val('Onderwerp');
            $(this).removeClass('focus');
        } 
    })    
    
    $('.contact_formulier #inhoud').focus(function() {
        $(this).addClass('focus');
        if($(this).val() == 'Inhoud') {
            $(this).val('');
        }
    })
    
    $('.contact_formulier #inhoud').focusout(function() {
        if($.trim($(this).val()).length == 0) {
            $(this).val('Inhoud');
            $(this).removeClass('focus');
        } 
    })

    $("#slider ul").children('li').removeClass('active invisible');
    $("#slider").easySlider();

    $(".thumbnail", ".advertentieMediaSelector").each(function() {
        var a = $(this).find('a');
        var type = a.attr("alt");
        var href = a.attr("href");
        if(type == '2') { setYoutube(href) }
        $(this).click(function(){
            if(!$(this).hasClass('hide')) {
                $(this).addClass('hide');
                $('.thumbnail').not(this).each(function(){
                    $(this).removeClass('hide');
                });
                if(type == '2') {
                    $(".main_image").fadeOut(300, function() {
                    $("#youtube_video").show(); })
                } else {
                    $("#youtube_video").hide();
                    $(".main_image").fadeOut(300, function() {
                        $(this).attr({src: href}).fadeIn(300);
                    });
                }
            }
            return false;
        });
    });

})

function setTwitterfountain(twitter_keyword)
{
    var tf='<script type=\'text/javascript\' src="http://www.twitterfountain.com/embed/twitterfountain.js?fv_twitterkeyword='+twitter_keyword+',fv_imagekeyword='+twitter_keyword+',fv_parseimagelinks=true,fv_messagespeed=15,fv_messageinterval=10,fv_messageanimation=2,fv_messagescale=1,fv_showbox=true,fv_imagespeed=6,fv_coloreffect=false,fv_imageanimation=0,fv_imagesource=0,fv_updateinterval=1,fv_hidesettingsbutton=true,fv_showtitle=false,fv_titlemessage=,fv_backcolor=b94263,fv_frontcolor=e76182,fv_logoimage=,fv_bgimage=http%3A//,fv_loadkanji=true,width=250,height=200"><\/script><object type="application/x-shockwave-flash" data="http://www.twitterfountain.com/twitterfountain.swf" width="250" height="200" id="twitterfountain-1848283762" style="visibility: visible; "><param name="allowScriptAccess" value="always"><param name="allowFullScreen" value="true"><param name="scale" value="noscale"><param name="salign" value="lt"><param name="bgcolor" value="#b94263"><param name="menu" value="false" /><param name="quality" value="high" /><param name="flashvars" value="fv_twitterkeyword='+twitter_keyword+'&amp;fv_imagekeyword='+twitter_keyword+'&amp;fv_parseimagelinks=true&amp;fv_messagespeed=15&amp;fv_messageinterval=10&amp;fv_messageanimation=2&amp;fv_messagescale=1&amp;fv_showbox=true&amp;fv_imagespeed=6&amp;fv_coloreffect=false&amp;fv_imageanimation=0&amp;fv_imagesource=0&amp;fv_updateinterval=1&amp;fv_hidesettingsbutton=true&amp;fv_showtitle=false&amp;fv_titlemessage=&amp;fv_backcolor=b94263&amp;fv_frontcolor=e76182&amp;fv_logoimage=http://&amp;fv_bgimage=http://&amp;fv_loadkanji=true&amp;width=250&amp;height=200&amp;fv_showblogbutton=false&amp;fv_showupgrademessage=false" /></object>';
    document.getElementById("twitterfountain").innerHTML = tf;
    document.getElementById("twitterfountain").style.display = "block";
}

function setYoutube(id) {
    var video_id = id.split('v=')[1];
    var ampersandPosition = video_id.indexOf('&');
    if(ampersandPosition != -1) {
        video_id = video_id.substring(0, ampersandPosition);
    }
    var href = 'http://www.youtube.com/v/' + video_id + '?enablejsapi=1&playerapiid=ytplayer';
    var params = { allowScriptAccess: "always", allowFullScreen: "true"};
    var atts = { id: "youtubeObject" };
    swfobject.embedSWF(href,
    "youtubeVideo", "300", "280", "8", null, null, params, atts);
}
