Cufon.replace('#navigation .hNavi a,.new h2, .product > h2 > span, .footer .adv-new h3, .header .quick-access > ul >li > a, .block h2, .col-main > div.main-article > div > h2 > span, div.select-type > input, div.cmf-skinned-text, #navigation a > b, div.other-list > h2 > span, .details > div.details-description > h2, .details > div.details-description > div.add-to-cart > a,li#process button, #checkout > div > h2, #checkout > button, .account-login h1,.account-login .new-users h2,.account-login .registered-users h2,.account-manage h1,.account-manage .fieldset .legend,.account-create h1, .account-create .fieldset h2, .block .block-title strong span,.fieldset .legend,.page-title h1, .page-title h2,.dashboard .box-info .box-head h2');

Cufon.replace('.left-nav',{hover: {color: 'white'}, hoverables: { li: true, a: true }});
Cufon.refresh();
// 
/* Sub navigation */
$j(document).ready(function() {
	$j("ul#topnav li").hover(function() {//Hover over event on list item
		$j(this).find("span").show(); //Show the subnav
                $j(this).find("span").addClass("hover");
		Cufon.refresh();
	} , function() { //on hover out...
		$j(this).find("span").hide();
		Cufon.refresh();//Hide the subnav
	});
});


$j(document).ready(function() {
	$j('.qty').selectBox();
});

$j(document).ready(function () {
    if (document.getElementById("left-nav")) {
        $j("#left-nav").children("ul").children("li").each(function () {
            $j(this).click(function () {
                window.location = $j(this).children("a").attr("href");
            })
        })
    }    
})

$j(document).ready(function () {
    $j(".links").children("li").each(function () {
        if ($j(this).attr("class") && ($j(this).attr("class").toString().trim() == "first" || $j(this).attr("class").toString().trim() == "last")) {
            $j(".welcome-msg").append($j(this).detach());
        }
    })
})

$j(document).ready(function () {   
    if (document.getElementById("pager")) {
        var pager = $j("#pager").detach();
        $j(".main-list").append(pager);
        var limiter = $j(".number-text").detach();
        $j(".sort-type").children("div").append(limiter);
        var limiter = $j(".number-value").detach();
        $j(".sort-type").children("div").append(limiter);
        
        // -- Creation of bottom pagination --
        
        // -- Location begin page --
        var location = window.location.toString();
        if (location.indexOf("p=")>=0) {
            var firstPart = location.substring(0,location.indexOf("p="));
            var secondPart = location.substring(location.indexOf("p="));
            if (secondPart.indexOf("&")>=0) {
                secondPart = secondPart.substring(secondPart.indexOf("&")+1);
                secondPart += "&";
            }
            else {
                secondPart="";
            }
            location = firstPart+secondPart+"p=1";
        }
        else {
            if (location.indexOf("?")>=0) {
                location = location+"&p=1";
            }
            else {
                location = location+"?p=1";
            }
        }
        $j("#pager").append('<div class="begin"><a href="'+location+'">&laquo; Begin</a></div>');
        
        // -- Pagination --
        var contentNumber = '<div class="number">';
        
        location = window.location.toString();
        var currentPage = 1;
        if (location.indexOf("p=")>=0) {
            var params = location.substring(location.indexOf("p="));
            if (params.indexOf("&")>=0) {
                currentPage = params.substring(0, params.indexOf("&"));
                currentPage = currentPage.replace("p=","");
            }
            else {
                currentPage = params.replace("p=","");
            }
        }
        urlPrevious = window.location.toString();
        if (currentPage > 1) {
            urlPrevious = window.location.toString().replace("p="+currentPage,"p="+(currentPage-1))
        }
        
        contentNumber += '<a class="before" href="'+urlPrevious+'">« Vorige</a>';
        
        var lastPage = 0;
        nextPage = 0;
        $j(".pages").children("ol").children("li").each(function () {
            if ($j(this).html().indexOf("previous") < 0 && $j(this).html().indexOf("next") < 0) {
                if ($j(this).html().indexOf("a")>=0) {
                    contentNumber += $j(this).html();
                }
                else {
                    contentNumber += '<a class="active" href="'+window.location.toString()+'">'+$j(this).html()+'</a>';
                    nextPage = parseInt($j(this).html())+1;
                }
                lastPage ++;
            }
        });
        
        location = window.location.toString();
        if (nextPage <= lastPage) {
            if (location.indexOf("p=")>=0) {
                location = location.replace("p="+currentPage, "p="+nextPage);
            }
            else {
                if (location.indexOf("?")>=0) {
                    location = location+"&p="+nextPage;
                }
                else {
                    location = location+"?p="+nextPage;
                }
            }
        }
        
        var nextPage = '<a class="next" href="'+location+'">Volgende »</a>';
        contentNumber += nextPage;

        contentNumber += '</div>';
        
        $j("#pager").append(contentNumber);
        
        // -- end div --
        location = window.location.toString();
        if (location.indexOf("p=")>=0) {
            location = location.replace("p="+currentPage,"p="+lastPage);
        }
        else {
            if (location.indexOf("?") >= 0) {
                location = location+"&p="+lastPage;
            }
            else {
                location = location+"?p="+lastPage;
            }
        }
        var endContent = '<div class="end"><a href="'+location+'">Einde »</a></div>';
        
        $j("#pager").append(endContent);
                
        $j(".pages").remove();
        
        if ($j("#price option").length == 1) {
            
            $j.post("/pricemanager/index/get",
                {category: $j("#param-current-category").val()},
                function(data){
                    var listPrice = data;
                    listPrice = listPrice.split(";");

                    var htmlSelect = '<select id="price" class="selectBox" onchange="setLocation(this.value)" name="price"">';

                    for (i=0;i<listPrice.length; i++) {
                        var item = listPrice[i].split(",");
                        htmlSelect += '<option value="'+item[0]+'">'+item[1]+'</option>';
                    }

                    htmlSelect += "</select>";

                    $j(".price-value").html(htmlSelect);
                    $j("#price option").each(function () {
                        if ($j(this).val() == window.location.toString()) {
                            $j(this).attr("selected","selected");
                        }
                    })
                    
                    $j('#price').selectBox();
                },'html'
            );
        }
        else {
            var listPrice = "";
            $j("#price").children("option").each(function () {
                if (listPrice !== "") {
                    listPrice += ";";
                }
                var item = $j(this).attr("value")+","+$j(this).html();
                listPrice += item;
            });
            
            $j.post("/pricemanager/index/save",
                {category: $j("#param-current-category").val(),data: listPrice},
                function(data){
                    
                },'html'
            );
            //setCookie("price-list-split-"+$j("#param-current-category").val(),listPrice,365);
            $j('#price').selectBox();
        }
        
        $j('#op').selectBox();
        $j('#number').selectBox();
        
        $j("#op_container").children("ul").children("li").click(function () {
            var url = $j(this).attr("id").replace("op_input_","");
            window.location = url;
        });
        
        $j("#price_container").children("ul").children("li").click(function () {
            var url = $j(this).attr("id").replace("price_input_","");
            window.location = url;
        });
        
        $j("#number_container").children("ul").children("li").click(function () {
            var url = $j(this).attr("id").replace("number_input_","");
            window.location = url;
        });
        
        if ($j(".number").children("a").length == 2) {
            $j("#pager").css("display","none");
        }
    }
    
    if (document.getElementById("no-product")) {
        $j("#no-product").attr("href",$j("#left-nav").children("ul").children(".current").children("a").attr("href"));
    }
    
    $j('#cat').selectBox().change(function () {
        window.location = $j(this).val();
    });   
    
    $j(".price-text").children("label").html("Prijscategorie:");
    
})

$j(document).ready(function () { 
    $j("#cat_container").children("ul").children("li").each(function () {
        $j(this).click(function () {
            window.location = $j(this).attr("id").replace("cat_input_","");
        });
    });
})

function submitQuestion () {
    $j(".col-main").children(".messages").remove();
    var valid = true;
    var errorMessage = "";
    if (!checkEmail($j("#question").children("#email").val())) {
        valid = false;
        errorMessage += "<li><span>Er was een probleem met uw vraag: Vul een geldig e-mailadres in.</span></li>";
    }
    if ($j("#name").val().length == 0) {
        valid = false;
        errorMessage += "<li><span>Er was een probleem met uw vraag: Naam is niet valide.</span></li>";
    }
    if ($j("#content").val().length == 0) {
        valid = false;
        errorMessage += "<li><span>Er was een probleem met uw vraag: Vraag is niet valide.</span></li>";
    }
    if (valid) {
        $j("#question").submit();
    }
    else {
        $j(".col-main").prepend("<ul class='messages'><li class='error-msg'><ul>"+errorMessage+"</ul></li></ul>");
        window.scrollTo(0,0);
    }
    return false;
    
}

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function getBaseUrl () {
    var pathArray = window.location.toString().split( '/' );

    return pathArray[0]+"/"+pathArray[1]+"/"+pathArray[2];
}

function checkEmail(email) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
        return (true);
    }
    return (false);
}

/*Footer logo hover*/
$j(document).ready(function(){
   $j(".imgHoverable").hover( function() {
       var hoverImg = HoverImgOf($j(this).attr("src"));
       $j(this).attr("src", hoverImg);
     }, function() {
       var normalImg = NormalImgOf($j(this).attr("src"));
       $j(this).attr("src", normalImg);
     });
});

function HoverImgOf(filename)
{
   var re = new RegExp("(.+)\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1-hover.$2");
}
function NormalImgOf(filename)
{
   var re = new RegExp("(.+)-hover\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1.$2");
}

$j(document).ready(function () {
    set2linesheight ();
})

function set2linesheight () {
    $j(".product-title").each(function () {
        if ($j(this).children("a").html().length > 35) {
            $j(this).children("a").html($j(this).children("a").html().substring(0,30)+" ...");
        }
        /*var divHeight = parseInt($j(this).children("a").height());
        var fontSize = $j(this).children("a").css('font-size');
        var lineHeight = parseInt(fontSize.replace('px','')) * 1.5;
        var lines = Math.round(divHeight / lineHeight);
        var modify = false;
        while (lines > 2) {
            modify = true;
            $j(this).children("a").html($j(this).children("a").html().substring(0,$j(this).children("a").html().length - 1));
            divHeight = parseInt($j(this).children("a").height());
            fontSize = $j(this).children("a").css('font-size');
            lineHeight = parseInt(fontSize.replace('px','')) * 1.5;
            lines = Math.round(divHeight / lineHeight);
        }
        if (modify) {
            $j(this).html($j(this).html().substring(0,$j(this).html().length - 11)+" ...");
        }*/
    })
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

$j(document).ready(function () {
    constructFooter ();
})

function constructFooter () {
    $j(".block-link-footer .col-1").html($j(".nav-1").html());
    $j(".block-link-footer .col-2").html($j(".nav-2").html()+'<div class="separator"></div>'+$j(".nav-3").html());
    $j(".block-link-footer .col-3").html($j(".nav-4").html());
    $j(".block-link-footer .col-4").html($j(".nav-5").html()+'<div class="separator"></div>'+$j(".nav-6").html());
    $j("#footer-list").remove();
    
    for (i=1;i<=4;i++) {
        var num = 1;
        var max = 9;
        $j(".block-link-footer .col-"+i).find("a").each(function () {
            if (num > max) {
                $j(this).parent().hide();
            }
            num++;
        });
    }
}

$j(document).ready(function () {
    var count = 0;
    $j(".bank-logo").children("p").children("a").each(function () {
        count++;
        if (count>7) {
            $j(this).hide();
        }
    })
})

$j(document).ready(function () {
    addSubmenuTopItem ();
    displayPromotion ();
    removeSpanTitle ();
    
    $j("#price_container").css("width","100px");
});

function addSubmenuTopItem () {
    $j("#topnav").children("li").each(function () {
        if ($j(this).attr("id") == "sub") {
            var url = $j(this).children("b").children("a").attr("href");
            var name = $j(this).children("b").children("a").html();
            
            $j(this).find("a").each(function () {
                $j(this).html($j(this).html().trim());
            })
            
            $j(this).children("span").prepend('<span class="level1 nav-1-0"><a href="'+url+'">Overzicht '+name+'</a></span>');
        }
    })
}

function displayPromotion () {
    $j(".promotion").each(function () {
        $j(this).show();
    })
}

function removeSpanTitle () {
    $j(".links").children("li").children(".top-link-cart").attr("title",$j(".links").children("li").children(".top-link-cart").attr("title").replace("<span>","").replace("</span>",""));
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

$j(document).ready(function () {
    $j(".input-region").children("input").each(function () {
        if($j(this).attr("id") == "shipping:region") {
            $j(this).css("display","none");
        }
    })
})

$j(document).ready(function () {
    $j(".price-box").each(function () {
        if ($j(this).children(".special-price").length > 0) {
            var price = $j(this).children(".special-price").children(".price").html();
            $j(this).parent(".product-price").children(".price").html(price);
        }
    })
})

$j(document).ready(function () {
    $j("#topnav").find(".level2").each(function () {
        $j(this).remove();
    })
})

function number_format (number, decimals, dec_point, thousands_sep) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // +      input by: Amirouche
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    // *    example 13: number_format('1 000,50', 2, '.', ' ');
    // *    returns 13: '100 050.00'
    // Strip all characters but numerical ones.
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}

/*$j(document).ready(function () {
    if ($j(".success-msg")) {
        var content = $j(".success-msg").children("ul").children("li").children("span").html();
        if (content == "Bedankt voor uw vraag. Wij nemen binnen 2 werkdagen contact met u op.") {
            // -- question case --
            _gat._getTrackerByName()._trackEvent("Question", "ask");
        }
        if (content == "Hartelijk dank voor uw inschrijving") {
            // -- newsletter case --
            _gat._getTrackerByName()._trackEvent("Newsletter", "registration");
        }
    }
})*/
