

        var blank = new Image();
        blank.src = 'http://www.savetodaysavetomorrow.com/images/blank.gif';

        var boxLeft = -449;
        var itemWidth = 449;
        var itemHeight = 374;
        var itemTop = 0;
        var scrollSpeed = 1500;
        var itemNo = 4;
        var currentItem = 4;
        var moveItemForward;
        var moveItemBackward;


        $(document).ready(function() {

            myBrowser = navigator.userAgent.substring(13, 16);
            myPlatform = navigator.userAgent.search(/Safari/);
            if (myBrowser == "Mac") {
                $("#mainNavLast").addClass("last-mac");
            }

            if (myPlatform != -1) {
                $("#mainNavLast").addClass("last-saf");
            }


            var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
            if (badBrowser) {
                // get all pngs on page
                $('img[src$=.png]').each(function() {
                    if (!this.complete) {
                        this.onload = function() { fixPng(this) };
                    } else {
                        fixPng(this);
                    }
                });
            }


            $('#pagination .dot_' + currentItem).animate({ opacity: 1 }, 800);
            headline_interval = setInterval(headline_rotate_forward, 8000);
            //css
            $(".scrollingFeature").css("position", "absolute");
            $("#features").css("overflow", "hidden");
            $("#features").css("height", 374);
            $("div#scrollpanel").css("position", "absolute");
            $("div#scrollpanel").css("overflow", "hidden");
            $("div#scrollpanel").css("width", 1796);
            $("div#scrollpanel").css("height", 374);
            $("div#scrollpanel").css("top", 0);
            $("div#scrollpanel").css("left", boxLeft);
            $(".scrollingFeature").css("width", itemWidth);
            $(".scrollingFeature").css("height", itemHeight);
            $(".scrollingFeature").css("top", itemTop);
            $(".scrollingFeature").css("display", "block");
            $(".scrollingFeature p").css("width", 400);
            $("#item1").css("width", 413);
            $("#item3").css("width", 418);
            $(".molecules").css("top", 5);
            $("#containerScrollControls").css("display", "block");

            var i;
            for (i = 0; i < itemNo; i++) {
                $("div#item" + (i + 1)).css("left", (i * itemWidth));

            }

            function headline_rotate_reverse() {

                $("div#scrollpanel").animate({ left: boxLeft + itemWidth }, scrollSpeed, function() {

                    if (currentItem == 1) {
                        currentItem = itemNo;
                        moveItemForward = 0;
                    }
                    else {
                        currentItem--;
                        moveItemForward = currentItem;
                    }
                    $('#pagination .pagingDot').animate({ opacity: 0.2 }, 200);
                    $('#pagination .dot_' + currentItem).animate({ opacity: 1 }, 800);
                    $("div#item" + (moveItemForward + 1)).css("left", (-1 * itemWidth));
                    $("div#scrollpanel").css("left", boxLeft);
                    $(".scrollingFeature").each(function(index, domEle) {
                        $(domEle).css("left", $(domEle).position().left + itemWidth);
                    });

                });
                return false;
            }


            function headline_rotate_forward() {

                if (currentItem == itemNo) {
                    moveItemBackward = 0;
                    currentItem = 1;
                }
                else {
                    moveItemBackward = currentItem;
                    currentItem++;
                }
                //move the item to a position = box width + box left
                $("div#item" + (moveItemBackward + 1)).css("left", $("div#scrollpanel").css("width"));
                //move the box
                $("div#scrollpanel").css("left", boxLeft + itemWidth);

                $(".scrollingFeature").each(function(index, domEle) {
                    $(domEle).css("left", $(domEle).position().left - itemWidth);
                });
                $("div#scrollpanel").animate({ left: boxLeft }, scrollSpeed)
                $('#pagination .pagingDot').animate({ opacity: 0.2 }, 200);
                $('#pagination .dot_' + currentItem).animate({ opacity: 1 }, 800);
                return false;
            }

            $("#scrollBackwards").click(function() {
                clearInterval(headline_interval);
                headline_rotate_reverse();
                headline_interval = setInterval(headline_rotate_forward, 8000);
            });

            $("#scrollForwards").click(function() {
                clearInterval(headline_interval);
                headline_rotate_forward();
                headline_interval = setInterval(headline_rotate_forward, 8000);
            });






            /*
            Hostname + Section Name
            */

            var basePath = document.URL.split("//")[1];
            var hostName = basePath.split("/")[0];

            if (hostName.split(":")[0] == "localhost") { // If local...
                hostName = hostName + "/SaveTodaySaveTomorrow";
            } else if (hostName.split(".")[0] == "development") { // If Dev
                hostName = hostName + "/2009/EDF/SaveTodaySaveTomorrow";
            } else if (hostName.split(".")[0] == "staging") { // If Staging
                hostName = hostName + "/2009/EDF/SaveTodaySaveTomorrow";
            }

            var urlLength = document.URL.split("/").length - 2;
            var sectionName = document.URL.split("/")[urlLength];




            /* SCROLLER FOR TV PAGES */

            var TT_additional = 'easeInOutQuint';
            var TS_additional = 480;
            var busy = 0;

            /*
            Related Content
            */

            //        $(".related_content_container li").hover(function() {

            //        $(this).css({ 'background': "url(http://" + hostName + "/Images/Generic/related_item_top_over.gif) no-repeat" })
            //            $(this).css({ 'background': "url(http://" + hostName + "/Images/Generic/related_item_top_over.gif) no-repeat" })
            //            $(this).find(".related_content_item_content").css({ 'background': "url(http://" + hostName + "/Images/Generic/related_item_bottom_over.gif) no-repeat bottom" })
            //        }, function() {
            //            $(this).css({ 'background': "url(http://" + hostName + "/Images/Generic/related_item_top.gif) no-repeat" })
            //            $(this).find(".related_content_item_content").css({ 'background': "url(http://" + hostName + "/Images/Generic/related_item_bottom.gif) no-repeat bottom" })
            //        });

            $(".related_content_container li").click(function() {
                var linkURL = $(this).find('a').attr('href');
                window.location = linkURL
            });

            /*
            Initialise Related Content
            */

            initRelatedContent = function(parent) {
                
                // Get total children
                var totalChildren = $(parent + " ul").size();
                // Calculate widths
                var childWidth = 270;
                var containerWidth = totalChildren * childWidth;
                // ammount the parent will need to move to display each item
                var difference = childWidth;
                // Get the maximum left point (to stop it from falling off the edge of the world...)
                var endOfLine = containerWidth - difference;

                // Remove css scrollbar 
                $('div.related_content_mask').css("overflow", "hidden");

                if (totalChildren > 1) {
                    //var lis = $(parent + " ul").children().size();
                    $('div.related_content_mask').height($(parent).find('ul').height());
                }
                else {
                    var lis = $(parent + " ul").children().size();
                    if (lis < 4) {
                        $('div.related_content_mask').height(250);
                    }
                    else {
                        $('div.related_content_mask').height($(parent).find('ul').height());
                    }

                }
                

                // Set container width
                $(parent).width(containerWidth);

                if (totalChildren > 1) {

                    // Show controls
                    $('#related_content_controls').css("display", "block");
                    $('#related_content_controls .left').css("opacity", "0.2");
                    var dot = $('.paging_container').html();
                    $('.paging_container').empty();

                    $(parent).find('ul').each(
				function(i) {
                    var newDot = $("<img src=\"http://www.savetodaysavetomorrow.com/Images/paging_dot.gif\" class=\"pagingDot\" alt=\"dot\" />").addClass('dot_' + i).css('opacity', '0.2');
				    $('.paging_container').append(newDot);
				}
			);

                    $('.paging_container .dot_0').css('opacity', '1');

                    $('a.related_scroller').click(function() {

                        // store the clicked anchor as an object for ease of use in the function
                        var selectedLink = $(this);

                        // check current CSS left value and * 1 so its treated as a number not a string
                        var containerPosLeft = $(parent).css('left').split('px')[0] * 1;
                        //alert(containerPosLeft);

                        if (selectedLink.hasClass('left') && !busy && containerPosLeft != 0) {
                            // Prevent further calls
                            busy = 1;
                            // calculate new location
                            var newLoc = containerPosLeft + difference;

                            // Selection number
                            var nextNum = ((-containerPosLeft + childWidth) / childWidth) - 2;
                            var prevNum = nextNum + 1;

                            $('.paging_container .dot_' + prevNum).animate({ opacity: 0.2 }, 200);
                            $('.paging_container .dot_' + nextNum).animate({ opacity: 1 }, 200);

                            // if its the last element fade out controls					
                            if (newLoc == 0) {
                                $('#related_content_controls .left').animate({ opacity: 0.2 }, 200);
                            }
                            // animate content
                            $(parent).animate({ left: newLoc }, TS_additional, TT_additional, function() {
                                relatedComplete();
                            });
                            $('#related_content_controls .right').animate({ opacity: 1 }, 500);
                        }
                        if (selectedLink.hasClass('right') && !busy && containerPosLeft != -endOfLine) {
                            // Prevent further calls
                            busy = 1;
                            // calculate new location
                            var newLoc = containerPosLeft - difference;

                            // Selection number
                            var nextNum = ((-containerPosLeft + childWidth) / childWidth);
                            var prevNum = nextNum - 1;

                            $('.paging_container .dot_' + prevNum).animate({ opacity: 0.2 }, 200);
                            $('.paging_container .dot_' + nextNum).animate({ opacity: 1 }, 200);

                            // if its the last element fade out controls
                            if (newLoc == -endOfLine) {
                                $('#related_content_controls .right').animate({ opacity: 0.2 }, 200);
                            }
                            // animate content
                            $(parent).animate({ left: newLoc }, TS_additional, TT_additional, function() {
                                relatedComplete();
                            });
                            // Lazyness? Setting the opposte arrows oppacity to full evertyime instead of checking
                            // this isnt hard to update... just low on time as per...
                            $('#related_content_controls .left').animate({ opacity: 1 }, 500);
                        }

                        return false;
                    });

                } else {
                    $('a.related_scroller.right, a.related_scroller.left').hide();
                }

            };

            // Call Init related content function
            initRelatedContent(".related_content_container");

            /*
            Related Content scroller
            */

            relatedComplete = function() {
                busy = 0;
            }

            // Attach an action for when people click on the specified anchor
            $('a.additional').click(function() {

                // store the clicked anchor as an object for ease of use in the function
                var selectedLink = $(this);
                // grab the related content container by looking at the href of the clicked item
                var selected_id = selectedLink.attr('href');
                // store the related content container as an object for ease of use
                var selectedId = $(selected_id);

                // if the clicked anchor has the class more
                if (selectedLink.hasClass('more')) {
                    // animate the selected container
                    selectedId.animate({ height: 'show', opacity: 1 }, TS_additional, TT_additional, function() {
                        // once animation is complete remove the class more and add the class less
                        selectedLink.removeClass('more').addClass('less');
                    });
                    // if the clicked anchor does not have the class more
                } else {
                    // animate the selected container
                    selectedId.animate({ height: 'hide', opacity: 0 }, TS_additional, TT_additional, function() {
                        // once animation is complete remove the class less and add the class more
                        selectedLink.removeClass('less').addClass('more');
                    });
                };
                return false;
            });






        });


/* Outside of JQuery Document Ready */


function fixPng(png) {
    // get src
    var src = png.src;
    // set width and height
    if (!png.style.width) { png.style.width = $(png).width(); }
    if (!png.style.height) { png.style.height = $(png).height(); }
    // replace by blank image
    png.onload = function() { };
    png.src = blank.src;
    // set filter (display original image)
    png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}
