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

 Flipbox written by CrappoMan

 simonpatterson@dsl.pipex.com

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

function flipBox(b){var a;if(document.images["b_"+b].src.indexOf("_on")==-1){a=document.images["b_"+b].src.replace("_off","_on");document.getElementById("box_"+b).style.display="none";if(document.getElementById("box_"+b+"_diff")){document.getElementById("box_"+b+"_diff").style.display="block"}document.images["b_"+b].src=a;disply="none";now=new Date();now.setTime(now.getTime()+1000*60*60*24*365);expire=(now.toGMTString());document.cookie="fusion_box_"+b+"="+escape(disply)+"; expires="+expire}else{a=document.images["b_"+b].src.replace("_on","_off");document.getElementById("box_"+b).style.display="block";if(document.getElementById("box_"+b+"_diff")){document.getElementById("box_"+b+"_diff").style.display="none"}document.images["b_"+b].src=a;disply="block";now=new Date();now.setTime(now.getTime()+1000*60*60*24*365);expire=(now.toGMTString());document.cookie="fusion_box_"+b+"="+escape(disply)+"; expires="+expire}}function addText(f,i,a,e){if(e==undefined){e="inputform"}if(f==undefined){f="message"}element=document.forms[e].elements[f];element.focus();if(document.selection){var c=document.selection.createRange();var h=c.text.length;c.text=i+c.text+a;return false}else{if(element.setSelectionRange){var b=element.selectionStart,g=element.selectionEnd;var d=element.scrollTop;element.value=element.value.substring(0,b)+i+element.value.substring(b,g)+a+element.value.substring(g);element.setSelectionRange(b+i.length,g+i.length);element.scrollTop=d;element.focus()}else{var d=element.scrollTop;element.value+=i+a;element.scrollTop=d;element.focus()}}}function insertText(f,h,e){if(e==undefined){e="inputform"}if(document.forms[e].elements[f].createTextRange){document.forms[e].elements[f].focus();document.selection.createRange().duplicate().text=h}else{if((typeof document.forms[e].elements[f].selectionStart)!="undefined"){var a=document.forms[e].elements[f];var g=a.selectionEnd;var d=a.value.length;var c=a.value.substring(0,g);var i=a.value.substring(g,d);var b=a.scrollTop;a.value=c+h+i;a.selectionStart=c.length+h.length;a.selectionEnd=c.length+h.length;a.scrollTop=b;a.focus()}else{document.forms[e].elements[f].value+=h;document.forms[e].elements[f].focus()}}}function show_hide(a){document.getElementById(a).style.display=document.getElementById(a).style.display=="none"?"block":"none"}function correctPNG(){if(navigator.appName=="Microsoft Internet Explorer"&&navigator.userAgent.indexOf("Opera")==-1){for(var g=0;g<document.images.length;g++){var d=document.images[g];var f=d.src.toUpperCase();if(f.substring(f.length-3,f.length)=="PNG"){var b=(d.id)?"id='"+d.id+"' ":"";var e=(d.className)?"class='"+d.className+"' ":"";var h=(d.title)?"title='"+d.title+"' ":"title='"+d.alt+"' ";var c="display:inline-block;"+d.style.cssText;if(d.align=="left"){c="float:left;"+c}if(d.align=="right"){c="float:right;"+c}if(d.parentElement.href){c="cursor:hand;"+c}var a="<span "+b+e+h+' style="width:'+d.width+"px; height:"+d.height+"px;"+c+";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+d.src+"', sizingMethod='scale');\"></span>";d.outerHTML=a;g=g-1}}}}function getStyle(c,b){if(typeof c=="string"){var a=document.getElementById(c)}else{var a=c}if(a.currentStyle){var d=a.currentStyle[b]}else{if(window.getComputedStyle){var d=document.defaultView.getComputedStyle(a,null).getPropertyValue(b)}}return d};

/***********************************************

* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)

* This notice must stay intact for legal use.

* Visit http://www.dynamicdrive.com/ for full source code

***********************************************/

function getposOffset(a,d){var c=(d=="left")?a.offsetLeft:a.offsetTop;var b=a.offsetParent;while(b!=null){if(getStyle(b,"position")!="relative"){c=(d=="left")?c+b.offsetLeft:c+b.offsetTop}b=b.offsetParent}return c}function overlay(e,d,a){if(document.getElementById){var c=document.getElementById(d);c.style.display=(c.style.display!="block")?"block":"none";var b=getposOffset(e,"left")+((typeof a!="undefined"&&a.indexOf("right")!=-1)?-(c.offsetWidth-e.offsetWidth):0);var f=getposOffset(e,"top")+((typeof a!="undefined"&&a.indexOf("bottom")!=-1)?e.offsetHeight:0);c.style.left=b+"px";c.style.top=f+"px";return false}else{return true}}function overlayclose(a){document.getElementById(a).style.display="none"}NewWindowPopUp=null;function OpenWindow(d,c,a,b){if(NewWindowPopUp!=null){NewWindowPopUp.close();NewWindowPopUp=null}if(b==false){wtop=0;wleft=0}else{wtop=(screen.availHeight-a)/2;wleft=(screen.availWidth-c)/2}NewWindowPopUp=window.open(d,"","toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=yes,status=no,directories=no,resizable=yes,height="+a+",width="+c+",top="+wtop+",left="+wleft+"");NewWindowPopUp.focus()}function resize_forum_imgs(){var f;var e;if(self.innerWidth){e=self.innerWidth}else{if(document.documentElement&&document.documentElement.clientWidth){e=document.documentElement.clientWidth}else{if(document.body){e=document.body.clientWidth}else{e=1000}}}if(e<=800){f=200}else{if(e<1152){f=300}else{if(e>=1152){f=400}}}for(var c=0;c<document.images.length;c++){var b=document.images[c];if(b.className!="forum-img"){continue}var j=b.height;var a=b.width;var d=false;if(a<=j){if(j>f){b.height=f;b.width=a*(f/j);d=true}}else{if(a>f){b.width=f;b.height=j*(f/a);d=true}}var h=b.parentNode;var g=h.parentNode;if(h.className!="forum-img-wrapper"){continue}if(d){h.style.display="inline";if(g.tagName!="A"){h.onclick=new Function("OpenWindow('"+b.src+"', "+(a+40)+", "+(j+40)+", true)");h.onmouseover="this.style.cursor='pointer'"}}else{h.style.display="inline"}}return true}function onload_events(){resize_forum_imgs();correctPNG()}window.onload=onload_events;


window.onload = function(){

    try {

        if (forwardUrl); // will throw an exception if var does not exist

        var waitTime = 10; // seconds
        var fw = setTimeout("location.href='" + forwardUrl + "'", waitTime * 1000);

        // count down
        $("span.js_countdown").ready(function() {
            var countDownValue = $("span.js_countdown");
            var cd = setInterval(
                function(){
                    countDownValue.text(countDownValue.text() - 1);
                    if (countDownValue.text() == 0) {
                        clearInterval(cd);
                    }
                }, 1000
            );

            // stop countdown and forwarding
            $('a.js_stop_countdown').click(function(event){
                event.preventDefault();
                clearInterval(cd);
                clearTimeout(fw);
                $(this).parent().slideUp();
            });

        });

    } catch (e) {
        // nothing to do here
    }

}





$(document).ready(function(){

    // =========================================================================
    // FAQ
    // =========================================================================

    /* mark clicked faq item */
    $('body.page_faq #main ul li a').click(function(){
        id = $(this).attr('href');
        $('body.page_faq #main div.faq_entry').removeClass('current');
        $('body.page_faq #main div.faq_entry' + id).addClass('current');
    });

    /* mark entry on clicking title */
    $('body.page_faq #main div h2').click(function(){
        id = $(this).parent().attr('id').valueOf();
        window.location.hash = id;
        $('body.page_faq #main ul li a[href="#' + id + '"]').click();
    });

    /* pre load faq entry */
    $('body.page_faq #main div h2').each(function(){
        if ($(this).parent().attr('id').valueOf() == window.location.hash.split('#')[1]) {
            $('body.page_faq #main ul li a[href="' + window.location.hash +  '"]').click();
        }
        //console.log($(this).parent().attr('id').valueOf() + ' ' + window.location.hash.split('#')[1]);
    });


    // =========================================================================
    // ADDED
    // =========================================================================

    // select linkious address
    $('input.linkious_address').select();
    $('input.linkious_address').live('focus click', function(){
        $(this).select();
    });


    // =========================================================================
    // ADD
    // =========================================================================

    // global element in which the inputs are
    var el = 'p.url_inputs';

    /* class name of an empty url (greyed out) */
    var emptyClassName = 'empty_url';


    /* unmark the inputs which might have changed */
    $('input.invalid_url').blur(function(){
        $(this).removeClass('invalid_url');
    });


    /* checks wether a string is an empty url */
    function emptyUrl(str) {
        return (str == 'http://' || str == '');
    }


    /* counts empty inputs */
    function countEmpty() {
        var i = 0;
        $(el + ' input').each(function() {
            if (emptyUrl($(this).val())) {
                i++;
            }
        });
        return i;
    }


    /* counts non-empty inputs */
    function countNonempty() {
        return $(el + ' input').size() - countEmpty();
    }


    /* (un)populate the url inputs */
    function addInput() {
        $(el + ' input:last-child').clone(false).removeClass('invalid_url').appendTo(el).val('http://').addClass(emptyClassName);
    }
    function addInputCond() {
        if (countEmpty() < 3) {
            addInput();
        }
    }
    $(el).ready(function(){
        while (countEmpty() >= 4 || ( $(el + ' input[value!=\'http://\']').size() > 0 && countEmpty() >= 3) ) {
            $(el + ' input[value=\'http://\']:last').remove();
        }
        addInputCond();
    });
    $(el + ' input').live('focus', function(){
        addInputCond();
    });
    $('p.js_addmorelinks').css({'display' : 'block'}); // unhide
    $('p.js_addmorelinks a').click(function(){
        for (var i=1; i<=3; i++, addInput());
        return false;
    });


    /* grey out empty non-focused urls */
    $(el + ' input').each(function(){
        urlFadeOut($(this));
    });
    $(el + ' input').live('focus', function(){
        $(this).removeClass(emptyClassName);
    });
    $(el + ' input').live('blur',  function(){
        urlFadeOut($(this));
    });
    $(el + ' input:first').blur(function(){
        if (countNonempty() == 0) {
            $(this).removeClass(emptyClassName);
        }
    });
    function urlFadeOut(e) {
        if (emptyUrl(e.val())) {
            e.addClass(emptyClassName);
        }
    }


    /* focus first url input */
    $(el + ' input:first').focus();



    //*
    // =========================================================================
    // LINK LIST
    // =========================================================================

    //$('ul.links .flash_video object, ul.links .flash_video embed').css({width : '142px'}).css({height : '115px'});
    $('div#linklist div.preview_youtube').live('click', function(event){
        v_id = $(this).children('.js_val').val();
        v_w  = '425';
        v_h  = '350';

        if (v_id != '') {

            // stop forwarding
            $('a.js_stop_countdown').click();

            event.preventDefault();

            $(this).find('img.foreground').animate({'opacity' : '0'}, 100);
            $(this).css({'float' : 'none', 'max-height' : v_h + 'px'});
            $(this).parent().children('p').animate({'margin-left' : '0'}, 100);
            $(this).children('a').children('img').animate({height : v_h + 'px', width : v_w + 'px'}, 600);
            $(this).animate({height : v_h + 'px', width : v_w + 'px'}, 600, function(){
                v = '<object width="' + v_w + '" height="' + v_h + '">';
                v = v + '<param name="movie" value="http://www.youtube-nocookie.com/v/' + v_id + '&amp;autoplay=1&amp;fs=1"></param>';
                v = v + '<param name="allowFullScreen" value="true"></param>';
                v = v + '<param name="allowscriptaccess" value="always"></param>';
                v = v + '<embed src="http://www.youtube-nocookie.com/v/' + v_id + '&amp;autoplay=1&amp;fs=1" type="application/x-shockwave-flash" ';
                v = v + 'allowscriptaccess="always" allowfullscreen="true" autoplay="1" width="' + v_w + '" height="' + v_h + '"></embed>';
                v = v + '</object>';
                $(this).html(v);
            });
        }

        // remove class to stop 'click' triggers
        $(this).removeClass('preview_youtube').addClass('preview_youtube_show');
    });
    //*/

});
