$(document).ready(function() {

    // Rounded corners
    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
    } else {
        $('.rounded').each(function() {
            var markup = '<span class="tl"></span><span class="tr"></span><span class="bl"></span><span class="br"></span>';
            markup += $(this).html();
            $(this).html(markup);
        });
    }

    // Heading - branding
    $('#nav h2').each(function() {
        return;
        var heading = $(this).html();
        var hdfirstchar = heading.charAt(0).toLowerCase();
        var hdrestofstring = heading.substring(1, 500);
        var lpadding = 106;
        if (hdfirstchar == 'd') {
            lpadding = 108;
        }
        if (hdfirstchar == 'g') {
            lpadding = 109;
        }
        if (hdfirstchar == 'i') {
            lpadding = 87;
        }
        if (hdfirstchar == 'j') {
            lpadding = 98;
        }
        if (hdfirstchar == 'l') {
            lpadding = 102;
        }
        if (hdfirstchar == 'm') {
            lpadding = 114;
        }
        if (hdfirstchar == 'o') {
            lpadding = 111;
        }
        if (hdfirstchar == 's') {
            lpadding = 102;
        }
        if (hdfirstchar == 't') {
            lpadding = 102;
        }
        if (hdfirstchar == 'w') {
            lpadding = 116;
        }
        if (hdfirstchar == 'y') {
            lpadding = 104;
        }
        $(this).html(hdrestofstring);
        $(this).css('padding', '0 0 0 ' + lpadding + 'px');
        $(this).css('background', 'url(\'/layout/heading_letters/sma_' + hdfirstchar + '.gif\')  0px 7px no-repeat');
    });

    // Set up topnav / lhnav timers
    var navOpenTimers = [];
    var navCloseTimers = [];
    var lhNavFadeState = [];
    var lhNavFadeTimers = [];

    // Top nav effects
    $("#nav").children('ul').children('li').hover(
         function() {
             var id = $.data(this);
             var $this = $(this);
             if (navCloseTimers[id] != "") {
                 clearTimeout(navCloseTimers[id]);
             }
             $this.siblings('li').children('ul').css("display", "none");
             navOpenTimers[id] = setTimeout(function() {
                 //$this.children("ul").css("display", "block");
                 $this.children('ul').fadeIn(300);
                 navOpenTimers[id] = "";
             }, 100);
         },
         function() {
             var id = $.data(this);
             var $this = $(this);
             if (navOpenTimers[id] != "") {
                 clearTimeout(navOpenTimers[id]);
             } else {
                 navCloseTimers[id] = setTimeout(function() {
                     $this.children("ul").css("display", "none");
                     //$this.children( 'ul' ).fadeout( 300 );  
                     navCloseTimers[id] = "";
                 }, 200);
             }
         }
	);

    $('#viewstockbtn').click(function() {
        window.location = "/stock-lists/ogilvie.aspx?ven=ogilvie";
    });
    $('#playdemobtn').click(function() {
        viewDemo('LR56ATF');
    });
$('#viewstockbtn-2').click(function() {
        window.location = "/stock-lists/ogilvie.aspx?ven=ogilvie";
    });
    $('#playdemobtn-2').click(function() {
        viewDemo('LR56ATF');
    });
$('.sma-video a').click(function() {
        viewVideo($(this).parent('div').attr("id"), $(this).parent('div').attr("regno"));
        return false;
    });

$('#sale_plan').click(function() {

        var top;
        var left;
        top = ($(window).height() - 550) / 2;  //+ $(window).scrollTop();
        left = ($(window).width() - 800) / 2 + $(window).scrollLeft();
        if ($(window).height() < $(document).height()) {
            $('#pdfviewermodal').attr('style', 'width: ' + $(document).width() + 'px; height: ' + $(document).width() + 'px;');
        }
        else {
            $('#pdfviewermodal').attr('style', 'width: ' + $(window).width() + 'px; height: ' + $(window).width() + 'px;');
        }
        $('#pdfviewermodal').show();
        $('#pdfviewerclose').click(function() {            
            $('#pdfviewermodal').hide();
            $('#pdfviewer').hide();
        });
        $('#pdfviewer').attr("style", "top: " + top + "px; left: " + left + "px;");
        $('#pdfviewer').show();
        return false;
    });

$(document).keyup(function(e) {
        if (e.keyCode == 27) {
            $('#pdfviewermodal').hide();
            $('#pdfviewer').hide();
            }
        });

$('.voucherbtn').click(function () {
        var top;
        var left;
        top = ($(window).height() - 550) / 2;  //+ $(window).scrollTop();
        left = ($(window).width() - 800) / 2 + $(window).scrollLeft();
        if ($(window).height() < $(document).height()) {
            $('#pdfviewermodal').attr('style', 'width: ' + $(document).width() + 'px; height: ' + $(document).width() + 'px;');
        }
        else {
            $('#pdfviewermodal').attr('style', 'width: ' + $(window).width() + 'px; height: ' + $(window).width() + 'px;');
        }
        $('#pdfviewermodal').show();
        $('#pdfviewerclose').click(function () {
            $('#pdfviewermodal').hide();
            $('#pdfviewer').hide();
        });
        $('#pdfviewer').attr("style", "top: " + top + "px; left: " + left + "px;");
        $('#pdfviewer').show();

        $(document).keyup(function (e) {
            if (e.keyCode == 27) {
                $('#pdfviewermodal').hide();
                $('#pdfviewer').hide();
            }
        });

        return false;
    });

});


function reportSelectedAuct() {
    //var combo1 = document.getElementById("SearchForm_auctionCat");
    var combo1 = document.getElementById('ctl00_Search1_auctionCat');
    var val = combo1.options[combo1.selectedIndex].value;
    window.open(val);
}


function viewDemo(regNo) {
    var top;
    var left;
    top = ($(window).height() - 480) / 2;  //+ $(window).scrollTop();
    left = ($(window).width() - 640) / 2 + $(window).scrollLeft();    
    var ivElement = '';
    if ($(window).height() < $(document).height()) {
        ivElement += '<div id="imageviewermodal" style="width: ' + $(document).width() + 'px; height: ' + $(document).height() + 'px;"></div>';
    }
    else {
        ivElement += '<div id="imageviewermodal" style="width: ' + $(window).width() + 'px; height: ' + $(window).height() + 'px;"></div>';
    }
    ivElement += '<div id="imageviewer" style="top: ' + top + 'px; left: ' + left + 'px; width: 640px; height: 480px;">';
    ivElement += '<iframe style="position: absolute; z-index: 10000;" width="640" height="480" frameborder="0" scrolling="no" src="http://www.citnow.co.uk/archive/embed.php?location=smal&amp;sessionId=21192&amp;strreg=' + regNo + '">&amp;lt;a target="_blank" href="http://www.citnow.co.uk/archive/embed.php?location=smal&amp;amp;sessionId=21192&amp;amp;strreg=' + regNo + '"&amp;gt;' + regNo + '&amp;lt;br /&amp;gt;Phil Bevan&amp;lt;/a&amp;gt;</iframe>'
    ivElement += '<div id="imageviewerclose" style="z-index: 1000111;"><span>Close</span></div>'
    ivElement += '</div>';
    $('body').append(ivElement);
    $('#imageviewerclose').live("click", function() {
        $('#imageviewer').remove();
        $('#imageviewermodal').remove();
    });
}

function viewVideo(link, regNo) {    
    var top;
    var left;
    top = ($(window).height() - 480) / 2;  //+ $(window).scrollTop();
    left = ($(window).width() - 640) / 2 + $(window).scrollLeft();
    var ivElement = '';
    if ($(window).height() < $(document).height()) {
        ivElement += '<div id="imageviewermodal" style="width: ' + $(document).width() + 'px; height: ' + $(document).height() + 'px;"></div>';
    }
    else {
        ivElement += '<div id="imageviewermodal" style="width: ' + $(window).width() + 'px; height: ' + $(window).height() + 'px;"></div>';
    }
    ivElement += '<div id="imageviewer" style="top: ' + top + 'px; left: ' + left + 'px; width: 640px; height: 480px;">';
    ivElement += '<iframe style="position: absolute; z-index: 10000;" width="640" height="480" frameborder="0" scrolling="no" src="' + link + '">&amp;lt;a target="_blank" href="' + link + '"&amp;gt;' + regNo + '&amp;lt;br /&amp;gt;Phil Bevan&amp;lt;/a&amp;gt;</iframe>'
    ivElement += '<div id="imageviewerclose" style="z-index: 1000111;"><span>Close</span></div>'
    ivElement += '</div>';
    $('body').append(ivElement);
    $('#imageviewerclose').live("click", function() {
        $('#imageviewer').remove();
        $('#imageviewermodal').remove();
    });
}


