$(document).ready(function() {
    var pageName = $('body').attr('id');
    $('body').pngFix();
    
    if(pageName=='category'){
        $("p.to-top a").click(function(){
            $.scrollTo( 'body', 1100 );    
        });

        // Hidden to test something
        // $('.product p').hide();
        // $('.product').hover(function(){
        //     $(this).find("p").fadeIn('fast');
        // }, function(){
        //     $(this).find("p").hide();
        // })
    }
    
    /*if(pageName=='product'){
        $(".initZoom").jqzoom({zoomWidth : 417, zoomHeight: '500', xOffset: '21', position: 'right'});
        $("#main-image").append('<p>hover image to zoom</p>');
        // Swap images on click
        $("#thumbs a").click(function(){
            $(".initZoom").remove();
            var imgRef = $(this).attr('href');
            var imgBig = $(this).attr('rel');
            $("#thumbs").find("img").attr('class', '');
            $(this).find('img').attr('class', 'active');
            $("#main-image").html('<a href="'+imgBig+'" class="initZoom" title="Click to view a zoomed image"><img src="'+imgRef+'" alt="this is the main product image" /></a>');
            $(".initZoom").jqzoom({zoomWidth : 417, zoomHeight: '500', xOffset: '21', position: 'right'});
            $("#main-image").append('<p>hover image to zoom</p>');
            return false;
        });

        if($('a#size-guide')){
            var sizeguide = '<img src="' + $("#size-guide").attr('href') + '" alt="Size guide" />';

            $('body').append('<div id="sizeguide-pop" style="display: none;" class="popup"><span class="jqmClose">Close</span>' + sizeguide + '</div>');    
               $('#sizeguide-pop').jqm({ toTop : true, overlay : 20});
            // Sizeguide popup
            $('a#size-guide').click(function(){
                prodWidth = $("#sizeguide-pop").outerWidth();
                $left = (($(window).width()-(prodWidth+22))/2);
                $('#sizeguide-pop').jqmShow();
                   $("#sizeguide-pop").css('left', $left);
                $("#sizeguide-pop").css('width', (prodWidth-22));
                return false;
            })
        }

        if($('a#care-guide')){
            var care = '<img src="' + $("#care-guide").attr('href') + '" alt="Care guide" />';

            $('body').append('<div id="careguide-pop" style="display: none;" class="popup"><span class="jqmClose">Close</span>' + care + '</div>');    
               $('#careguide-pop').jqm({ toTop : true, overlay : 20});
            // Careguide popup
            $('a#care-guide').click(function(){
                
                prodWidth = $("#sizeguide-pop").outerWidth();
                $left = (($(window).width()-(prodWidth+22))/2);
                $('#careguide-pop').jqmShow();
                   $("#careguide-pop").css('left', $left);
                $("#careguide-pop").css('width', (prodWidth-22));
                return false;
            })
        }

        // The add to basket confirmation popup
        $('#added-to').jqm({ toTop : true, overlay : 05});
        $.displayAddConfirm = function() {
            leftBuy = (($(window).width()-962)/2)+(962-198);
            $("#added-to").css('left', leftBuy);
            $('#added-to').jqmShow();
            //var timer = setTimeout("$('#added-to').jqmHide();", 2700);
            return false;
            
        };

    }*/
    if(pageName=='latest-news'){
        $('.post-archive li span').toggle(
            function(){
                $(this).parent().addClass('on');
            },
            function(){
                $(this).parent().removeClass('on');
            }
        );
    }
        
    if(pageName=='buyline'){
        $('#csvhelp').jqm({ toTop : true, overlay : 0});    
        $('li.error').show('fast');

        // CSV popup
        $('a#csv').click(function(){
            
            prodWidth = $("#csvhelp").outerWidth();
            $left = (($(window).width()-(prodWidth+22))/2);
            $('#csvhelp').jqmShow();
               $("#csvhelp").css('left', $left);
            $("#csvhelp").css('width', (prodWidth-22));
            return false;
        })
    }
});
