// JavaScript Document

// email to a friend
function EmailLink() {
    window.location = "mailto:" + "?subject=Man Group plc Annual Report and Accounts 2009" + "&body=" + "I thought this link might interest you:  " + document.title + "  " + location.href;
}

// bookmark function
function Bookmark() {
    // Get title
    title = window.document.title;
    // Get url
    url = window.document.location;

    if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
        window.external.AddFavorite(url, title);
    else
        alert("Press CTRL-D (Firefox) or COMMAND-D(Safari) to bookmark this page");
}




$(document).ready(function () {

    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    //Zoom
    if (sPage == "DesignDetails.aspx") {

        if ($.fn.jqzoom) {
            if ($('.jqzoom').length > 0) {
                $('.jqzoom').jqzoom({
                    zoomType: 'standard',
                    lens: true,
                    preloadImages: true,
                    alwaysOn: false,
                    title: false,
                    zoomWidth: 435,
                    zoomHeight: 435,
                    xOffset: 2
                });
            }
        }
    }
    //Design details - Lightbox
    $('input[alt="Add to scrapbook"]').click(function () {
        showLightbox($('#addScrapbook_content'), 362);
    });

    $('.btn_close, .lb_content input[alt="Return to page"], .lb_overlay').click(function () { $('#lb_wrapper').hide(); });


    //	/**
    //	*JQuery Slider
    //	**/
    //	var openedBanner,clickedLI,index,timer  = null;
    //	var $bannerContainer = $('.banner_container');
    //	var $banners = $('.banner',$bannerContainer).hide(); 
    //	var banner_count = $banners.length;
    //	var $bannerCtrlContainer = $('.banner_controls_container ');
    //	var $ulPos = $('.banner_pos',$bannerCtrlContainer);
    //	var aniSpeed = 500;
    //	var pause = 5000;
    //	var $btnPlay = $('.banner_controls .play');

    //	
    //	//Create navigation dynamically based on the banner count
    //	if(banner_count){
    //		for(i=1; i<=banner_count; i++)
    //			$('<li>' + i + '</li>').appendTo($ulPos);
    //	}
    //	
    //	var $liPos = $ulPos.find('li');
    //	
    //	//Event handler
    //	var bannerAnimation = function(){
    //		index = $liPos.index(this);
    //		var curBanner = $banners[index];
    //		if(openedBanner){
    //			$(openedBanner).stop(true,true).fadeOut(aniSpeed);
    //			$(clickedLI).removeClass('selected');
    //		}
    //		$(curBanner).stop(true,true).fadeIn(aniSpeed);
    //		$(this).addClass('selected');
    //		clickedLI = this; openedBanner=curBanner;
    //		
    //		index++;
    //		return false;
    //	}
    //	
    //	//Based on click;
    //	$liPos.click(bannerAnimation).eq(0).click();
    //	
    //	
    //	//Timer function
    //	function autoAnimation(){
    //		if(index < banner_count){$liPos.eq(index).click();}
    //		else {index=0; $liPos.eq(index).click(); }
    //	}
    //	
    //	//Method to be called on clicking Prev & Next
    //	function controlPrevNext(isPrev)
    //	{
    //		pauseAutoAni($btnPlay[0]);
    //		index = isPrev ? index-2 : index;
    //		if(index < 0) index=banner_count-1;
    //		else if(index >= banner_count) index=0;
    //		$liPos.eq(index).click();
    //	}
    //	
    //	//Method to be called to start auto scroll
    //	function startAutoAni(elem)
    //	{
    //		$(elem).data('isPlay',true).attr('title','Pause').addClass('play');
    //		timer = window.setInterval(autoAnimation,pause);
    //	}
    //	
    //	//Method to be called to pause auto scroll
    //	function pauseAutoAni(elem)
    //	{
    //		$(elem).data('isPlay',false).attr('title','Play').removeClass('play');
    //		window.clearInterval(timer);
    //	}
    //	
    //	//Play / Pause event
    //	$btnPlay.data('isPlay',false).click(function(){
    //		if($(this).data('isPlay')){
    //			pauseAutoAni(this);
    //		}
    //		else{
    //			startAutoAni(this);
    //		}
    //	}).click();
    //	
    //	$('.banner_controls .prev').click(function(){controlPrevNext(true)});
    //	$('.banner_controls .next').click(function(){controlPrevNext(false)});
    //	
    //	
    //	//Banner hovering effect
    //	$banners.hover(function(){
    //		pauseAutoAni($btnPlay[0]);
    //		$(this).find('input[alt="Add to scrapbook"]').show();
    //	}, function(){
    //		startAutoAni($btnPlay[0]);
    //		$(this).find('input[alt="Add to scrapbook"]').hide();
    //	});

    /*Inspiration*/
    if ($.fn.jCarouselLite) {
        if ($('.inspire_thumb_container').length > 0) {
            $('.inspire_thumb_container').jCarouselLite({
                btnNext: ".btnNext",
                btnPrev: ".btnPrev",
                vertical: true,
                visible: 4,
                start: 0,
                circular: false,
                speed: 600
            });
        }
    }


    // Start the image tags
    if (typeof (ImageTagRotate) != "undefined") {
        ImageTagRotate.init();
    }

    $('.inspire_thumb').click(function () {
        $('.inspire_img_preview > img').attr('src', $(this).find('input[type="hidden"]').val());
    });

    $('.inspire_img_preview').hover(function () {
        $(this).find('input[alt="Add to scrapbook"]').show();
    }, function () {
        $(this).find('input[alt="Add to scrapbook"]').hide();
    });


});

//Method to call lightbox
function showLightbox(lb_content_box, width) {
    $('.lb_content_wrapper')
	.append($('.lb_content', lb_content_box))
	.css({ 'width': width, 'marginLeft': -(width / 2) });
    $('#lb_wrapper').show();
}

// Search box initialisation
// We should really only have one document ready
$(document).ready(function () {

    if ($("input.key_wrd").length) {
        $("input.key_wrd:not(.cms_view)").autocomplete({
            source: "SearchAutocomplete.aspx", appendTo: '#menuContainer'
        });
        $("input.key_wrd").labelswitch();
    }

});

// Code for switching a text box's label
(function ($) {

    $.fn.labelswitch = function () {
        return this.each(function () {
            var $this = $(this);

            function init() {
                $this.prev('label').hide();
                if ($this.val() == '' || $this.val() == $this.prev('label').text()) {
                    $this.addClass("empty");
                    $this.attr('label', $this.prev('label').text());
                    $this.val($this.prev('label').text());
                }
            }

            init();

            $this.focus(function () {
                var $t = $(this);
                if ($t.val() == "" || $t.val() == $t.attr('label')) {
                    $t.removeClass("empty");
                    $t.val("");
                }
            }).blur(function () {
                var $t = $(this);
                if ($t.val() == "") {
                    $t.val($t.attr('label'));
                    $t.addClass("empty");
                }
            });

        });
    };
})(jQuery);
