$(window).load(function() {

    $('.logo').ifixpng().css('cursor', 'pointer');
    $('.SubNavigation li a').ifixpng().css('cursor', 'pointer');
    $('.orange-bullet-list li').ifixpng();
    $('td.ms-sbgo a img').ifixpng();

    // DAJW design haus added check for js var set inline before this file loaded. Var is only set in edit mode of Publishing page.
    var sifrDisable = (typeof (sifrDisableFlag) != "undefined");

    if (!sifrDisable) {
        $('.professional-services').children('ul').hide();
        $('.business-services').children('ul').hide();

        // links go to pages, not interact with fader panel - commented out
        /*
        $('.managed-services>a').bind('click', openManagedServices);
        $('.professional-services>a').bind('click', openProfessionalServices);
        $('.business-services>a').bind('click', openBusinessServices);
	    
	    $('.managed-services>a').click(function() {
        clearTimeout(cycle2);
        clearTimeout(cycle1);
        clearTimeout(cycle3);
        });
        $('.professional-services>a').click(function() {
        clearTimeout(cycle2);
        clearTimeout(cycle1);
        clearTimeout(cycle3);
        });
        $('.business-services>a').click(function() {
        clearTimeout(cycle2);
        clearTimeout(cycle1);
        clearTimeout(cycle3);
        });
        */
    }
    else {
        $("body").addClass("editmode");
    }

    // make any sun catalogue links open in a new window
    $('a.suncat').bind('click', function() {
        selfPopup(this, 800, 600);
        return false;
    });

    // hover state for tables with listing class
    $('table.listing td').hover(
      function() {
          $(this).addClass("hover");
      },
      function() {
          $(this).removeClass("hover");
      }
    );

    // hover state for download panels for case studies
    $('.content-full-section').hover(
      function() {
          $(this).addClass("content-full-section-hover");
      },
      function() {
          $(this).removeClass("content-full-section-hover");
      }
    );

    // toggle the menu that selects the keyword filtering
    $('#csPop a[href="#"]').click(function() {
        g_bWarnBeforeLeave = false;
        $('#csPop ul').slideDown();
        return false;
    });
    $('#csPop ul a').click(function() {
        $('#csPop ul').slideUp();
        // set input value to href attr of clicked link
        $('input.casestudyfilterpicker').val($(this).attr('href'));
        g_bWarnBeforeLeave = true;
        return false;
    });



    // auto-rotate the homepage panels
    var cycle1, cycle2, cycle3;
    var duration_panel_visible = 8000; // total time each panel is visible
    var duration_slide_animation = 3500; // time taken for slide up/down animation for navigation links
    var duration_fade_animation = 2000; // time taken for main area fade in/out
    var getBusinessPosition = $('.business-services').attr('offsetTop');
    var setBusinessPosition = getBusinessPosition - 2;
    var setIEBusinessPosition = getBusinessPosition + 13; // IE's offset is different...

    function openManagedServices() {
        clearTimeout(cycle3);
        cycle1 = setTimeout(function() { openProfessionalServices() }, duration_panel_visible);
        $('.managed-services').siblings('li').removeClass('on');
        $('.managed-services').addClass('on');
        $('.homepage-cover').fadeIn(duration_fade_animation, function() {
            $('#professional-services-header').css('z-index', '-2');
            $('#business-services-header').css('z-index', '-2');
            $('#managed-services-header').css('z-index', '200');
        });
        $('.homepage-cover').fadeOut(duration_fade_animation);
        $('.managed-services').siblings('li').children('ul').slideUp(duration_slide_animation);
        $('.managed-services').children('ul').slideDown(duration_slide_animation);
        $('#HomeHeaderImage').fadeOut(duration_fade_animation, function() {
            $('#HomeHeaderImage').css('background', 'transparent url(furniture/images/header-image-1.jpg) no-repeat scroll left top').fadeIn(2000);
        });
        //$('#HomeHeaderInner').css('background', 'transparent url(furniture/images/header-image-1.jpg) no-repeat scroll right top');
    }

    function openProfessionalServices() {
        clearTimeout(cycle1);
        cycle2 = setTimeout(function() { openBusinessServices() }, duration_panel_visible);
        $('.professional-services').siblings('li').removeClass('on');
        $('.professional-services').addClass('on');
        $('.homepage-cover').fadeIn(duration_fade_animation, function() {
            $('#business-services-header').css('z-index', '-2');
            $('#managed-services-header').css('z-index', '-2');
            $('#professional-services-header').css('z-index', '200');
            $('.homepage-cover').fadeOut(duration_fade_animation);
        });
        $('.professional-services').siblings('li').children('ul').slideUp(duration_slide_animation);
        $('.professional-services').children('ul').slideDown(duration_slide_animation);
        $('.business-services').css('position', 'absolute').css('left', '35px');
        if ($.browser.msie) {
            $('.business-services').css('top', setIEBusinessPosition + 'px')
        } else {
            $('.business-services').css('top', setBusinessPosition + 'px')
        }
        $('#HomeHeaderImage').fadeOut(duration_fade_animation, function() {
            $('#HomeHeaderImage').css('background', 'transparent url(furniture/images/header-image-2.jpg) no-repeat scroll left top').fadeIn(2000);
        });
        //$('#HomeHeaderInner').css('background', 'transparent url(furniture/images/header-image-2.jpg) no-repeat scroll right top');
    }
    function openBusinessServices() {
        $('.business-services').removeAttr('style');
        clearTimeout(cycle2);
        cycle3 = setTimeout(function() { openManagedServices() }, duration_panel_visible);
        $('.business-services').siblings('li').removeClass('on');
        $('.business-services').addClass('on');
        $('.homepage-cover').fadeIn(duration_fade_animation, function() {
            $('#professional-services-header').css('z-index', '-2');
            $('#managed-services-header').css('z-index', '-2');
            $('#business-services-header').css('z-index', '200');
            $('.homepage-cover').fadeOut(duration_fade_animation);
        });
        $('.business-services').siblings('li').children('ul').slideUp(duration_slide_animation);
        $('.business-services').children('ul').slideDown(duration_slide_animation);
        $('#HomeHeaderImage').fadeOut(duration_fade_animation, function() {
            $('#HomeHeaderImage').css('background', 'transparent url(furniture/images/header-image-1.jpg) no-repeat scroll left top').fadeIn(2000);
        });
        //$('#HomeHeaderInner').css('background', 'transparent url(furniture/images/header-image-1.jpg) no-repeat scroll right top');


    }

    // kick off the animation
    cycle1 = setTimeout(function() { openProfessionalServices() }, duration_panel_visible);

});




// Usage:
//  renderGoogleMapEmbedded('IdOfInputControl'); - function will read value of input (hidden, text) control to geocode
//  renderGoogleMapEmbedded('', 'Bitterne Road, Southampton'); - function will use supplied address to geocode

function renderGoogleMapEmbedded(mapDataElement, addressSupplied)
{

	// render the google map
	var geocoder = null;
	var map = null;

	var lat=0.0;
	var lon=0.0;
	var address = "";
	var mapRenderElement = "map_canvas"; 


	// don't show in edit mode.
	if (typeof(disableGoogleMaps)!="undefined")
	{
		return;
	}

	if (GBrowserIsCompatible()) 
	{

		map = new GMap2(document.getElementById(mapRenderElement));
		map.setUIToDefault();
		geocoder = new GClientGeocoder();
		geocoder.setBaseCountryCode("uk");

		// add marker to map
		map.clearOverlays();

		// get address data
		if (typeof(addressSupplied)=="undefined")
		{
			address = $("#"+mapDataElement).val();
		}
		else
		{
			address = addressSupplied;
		}

		geocoder.getLatLng(address, function(point) 
		{

			if (!point) 
			{
				//alert(address + " not found by  google maps");
			}
			else
			{
				map.setCenter(point, 13);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				GEvent.addListener(marker , "click", function() 
				{
					window.open("http://maps.google.co.uk/maps?q="+address);
				});
			}
		});
	}
}



/* selfPopup
 * open popup window with href determined from the href attribute on the anchor:
 * <a href="index.html" onclick="selfPopup(this,300,400); return false;">Index</a>
 */
function selfPopup( loc, x, y ) {
   LeftPosition = (screen.width) ? (screen.width-x)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-y)/2 : 0;
   window.open(loc.href,"","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width="+x+",height="+y+',left='  +LeftPosition +  ',top='  +TopPosition +"");
}