window.strKeywordMaxTrackingURL = 'https://keywordmax.com/tracking/act.php?id=487548085&name=Click&trackall=1';

// javascript to support the default skin
function makeLink( keywords, search_url ){
    var link;
    link  = "<a href=\"" + search_url + "&keywords=" + escape(keywords) + 
        "\" class=\"searchDirLink\"><div class='dirLeft'>" + 
        keywords + "</div></a>";
    return link;
};

function make_thumb( img_attributes, width, height) {
	// If the image is wider or taller than 56, scale it down.
	if(width > height && width > 60)
	{
		height = 60 * height / width;
		width = 60;
	}
	else if(height > width && height > 56)
	{
		width = 60 * width / height;
		height = 60;
	}
    return '<img '+img_attributes+' height="'+height+'" width="'+width+'" />';
};

function trackClick(link, url, track_url, bid, tid, target)
{
    var img = new Image();
    url = url || link.href;
    var bTargetBlank = ((target || link.target || null) == '_blank');
    var gotolink = function() { 
        if(!bTargetBlank)
        {
            window.location = url;
        }
    };
    track_url = track_url || link.getAttribute("page_url") || strKeywordMaxTrackingURL;
    bid = bid || link.getAttribute('bid') || null;
    tid = tid || link.getAttribute('tid') || null;
    img.onload = gotolink;
    img.onerror = gotolink;

    if(bid !== null) {
        track_url += '&amount=' + bid;
    }
    if(tid !== null) {
        track_url += '&transid=' + tid;
    }
    img.src = track_url;
    return (bTargetBlank);
};

function addTracking(id)
{
    var links = document.getElementById(id).getElementsByTagName('A');

    for(var i=0; i<links.length; ++i)
    {
        var link = links[i];
        link.setAttribute('bid', '0');
        link.setAttribute('id', window.page_id + id + i);
        link.setAttribute("page_url", window.strKeywordMaxTrackingURL);
        link.onclick = function() { return trackClick(this);};
    }
};

function renderRating( fRating) {
    var stars='';
    var iRating = Math.floor(fRating);
    
    //add full stars
    for(i=0; i < iRating; i++) {
        stars += '<img width="28" height="19" src="' + window.theme_image_dir + 
            'star_rating.gif"/>';
    }
    //now add half stars
    var iHalf = fRating - iRating;
    if(0!=iHalf) {
        stars += '<img width="28" height="19" src="' + window.theme_image_dir + 'half_star_rating.gif" />';
    }
    return stars;
};


function blowupImage(sizeMult, bottomMult) {
    if($type(sizeMult) != 'integer' && $type(sizeMult) != 'float')
        sizeMult = null;
    var originalDim = this.getSize();
    sizeMult = sizeMult || 2;
    bottomMult = bottomMult || (-1 / 4);
    
    var newImg = $(this.getProperty("id") + "_big");
    
    newImg
        .setStyles({
            "width":  originalDim.size.x * sizeMult,
            "height": originalDim.size.y * sizeMult,
            position: "absolute",
            bottom: bottomMult * originalDim.size.y * sizeMult,
            left: 0,
            display: ""
            });    
};
function blowdownImage() {
    this.setStyles({
        display: "none"                                
        });
    this.bMouseOver = false;
};

// these functions will ensure that a quick mouseover doesn't leave the image blown up.
function checkBlowupImage() {
    var newImg = $(this.getProperty("id") + "_big");
    function tmp() {
        if(typeof(newImg.bMouseOver) == 'undefined' || 
            newImg.bMouseOver == null || 
            newImg.bMouseOver != true)
        {
            blowdownImage.bind(newImg)();
        }
    }
    tmp.delay(100);
};
function checkBlowdownImage() {
    this.bMouseOver = true;
};