
$(document).ready(function () {

// $.fixedIE();

    //only use on the homepages but not the root homepage

    if( ($("body.homepage").length>0)) {

        vAlign(); 
        
        
        $(window).resize(function() {
          vAlign(); 
        });

    }
    
    //Agency authors columns
    
    liLen = $("body.page-id-95 div.entry-content ul li").length;
    lisCol = parseInt(liLen/4);
    lis = $("body.page-id-95 div.entry-content ul li");
    $("body.page-id-95 div.entry-content ul").empty().addClass("ul0");
    for(a=3;a>0;a--) {
        $("body.page-id-95 div.entry-content ul.ul0").after('<ul class="ul' + a + '"></ul>');
    }
    uls=0;
    count=0;
    for(a=0; a<=lis.length; a++) {
        $("ul.ul" + uls).append(lis[a]);
        count++;
        if(count>=lisCol) {
            uls++;
            count=0;
        }
    }
    
    //start cycle on booshop homepage
    ul = $('div#slideshow ul');
    ul.cycle({
            fx: 'fade',
            height: largestSize(ul, true),
            width: largestSize(ul, false)
    }); 
});

function largestSize(x, isHeight) {
    h = 0;
    w = 0;
    x.find("li").each(function() {
            h = ($(this).height() >h) ? $(this).height() : h;
            w = ($(this).find("img").width() >w) ? $(this).find("img").width() : w;
    });
    
    return (isHeight) ? h : w;
}

function vAlign() {
    
    ch = ($("div#content").height());
    cw = ($("div#content").width());
    wh = ($(document).height());
    ww = ($(document).width());
    
    // only center if the documebt height is larger than the content height
    
    if(wh > ch) {
        $("div#content").css({
            position: "absolute",
            top: ((wh/2) - (ch/2)) + "px",
            left: "0px" 
        });
    } else {
        $("div#content").css({
            position: "relative",
            top: "0px",
            left: "0px"
        });
    }

}


