$(document).ready(function() {
    Cufon.replace('.snippet-2 h3');
    Cufon.replace('.snippet h3');
    Cufon.replace('.snippet-sml h3');
    Cufon.replace('.sSubjects ul li a');
    Cufon.replace('.snippet_tabs li h3 a');
    Cufon.replace('#contact-footer');
    Cufon.replace('.sectionHolder h3');
    Cufon.replace('.Box h3');
    Cufon.replace('.Box strong');
    Cufon.replace('.Box-2 h3');
    Cufon.replace('.Box-2 strong');
    Cufon.replace('.Box-3 h3');
    Cufon.replace('p.quote');
    Cufon.replace('.leftBoxContent h3');
    Cufon.replace('.contentSnippet h3');
    Cufon.replace('.leftSubnavBox h3');
    Cufon.replace('.mainContent h3');
    Cufon.replace('.mainContent h4.sub-head');
    Cufon.replace('.mainContent722 h3');
    Cufon.replace('.mainContent722 h4.sub-head');
    Cufon.replace('.diaryContent h3');
    Cufon.replace('.testimonial_content .profile h4');
    Cufon.replace('#afeature-box-list h4', { fontFamily: 'Colaborate' });
    Cufon.replace('#afeature-box-list p', { fontFamily: 'Colaborate' });


    // make list item clickable
    $(".sSubjects ul li").click(function() {
        window.location = $(this).find("a").attr("href"); return false;
    });

    // make homepage body snippet same height
    equalHeight($("body#home .snippet-sml .body, body#home .tab_content .body"));
    equalHeight($(".contentSnippet .bodyOutcome"));

    // tab content on homepage
    $(".tab_content").hide();
    $("ul.snippet_tabs li:first").addClass("active").show(function() {
        Cufon.replace('.snippet_tabs li.active h3 a');
    });
    $(".tab_content:first").show();
    $("ul.snippet_tabs li").click(function() {
        $("ul.snippet_tabs li").removeClass("active");
        Cufon.replace('.snippet_tabs li h3 a');
        $(this).addClass("active");
        $(".tab_content").hide();
        Cufon.replace('.snippet_tabs li.active h3 a');
        var activeTab = $(this).find("a").attr("href");
        $(activeTab).fadeIn();
        return false;
    });

    $("ul#tabs li a").click(function() {
        
        $("ul#tabs li a").removeClass("active");
        Cufon.replace('ul#tabs li h3 a');
        $(this).addClass("active");
        //$(".tab_content").hide();
        Cufon.replace('ul#tabs li h3 a.active');
        //var activeTab = $(this).find("a").attr("href");
        //$(activeTab).fadeIn();
        return false;
    });
    /*********  Google maps   *********/
    $(".map:first").show();
    $("ul.maps-link li:first").removeClass("active");
    $("ul.maps-link li").click(function() {
        $("ul.maps-link li").removeClass("active");
        //Cufon.replace('.snippet_tabs li h3 a');
        $(this).addClass("active");
        $(".map").hide();
        //Cufon.replace('.snippet_tabs li.active h3 a');
        var activeTab = $(this).find("a").attr("href");
        $(activeTab).fadeIn();
        return false;
    });
    /*********** END **********/


    // remove background from Box-3
    $(".rightContent .Box-3 .body ul li:last-child").css("background", "none");


    // subnav
    $(".leftSubnavBox ul li:first a:first").addClass("noBG");

    $(".leftSubnavBox ul li:first a:first").hover(
		function() {
		    $(this).removeClass("noBG");
		    $(this).addClass("pretty-hover");
		},
		function() {
		    $(this).addClass("noBG");
		    $(this).removeClass("pretty-hover");
		}
	);

    //$(".leftSubnavBox ul li:first a:first").css("background","none");


    // auto-fill search field
    autoFill($("#siteSearch"), "Type your search here");

    // drop down for quick facts
    $(".dropdown dt").click(function() {
        $(".dropdown dd ul").slideToggle();
    });
    $(".dropdown dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdown dt").html(text);
        $(".dropdown dd ul").hide();
    });
    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass("dropdown"))
            $(".dropdown dd ul").slideUp();
    });

    // create multi column list for footer
    //$('.link-list').makeacolumnlists({cols: 3, colWidth: 120, equalHeight: 'ul', startN: 1});
});

/**
 * Function 
 * Auto-fill search form fields
 */
function autoFill(id, v){
	$(id).css({ color: "#666666" }).attr({ value: v }).focus(function(){
		if($(this).val()==v){
			$(this).val("").css({ color: "#000" });
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).css({ color: "#666666" }).val(v);
		}
	});
}

/**
 * Function 
 * Make elements to equal height
 */
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

/*-------------------------- Google Maps functions --------------------------*/

    // class for holding map co-ordinates & map details
    function myMapObject(longitude,latitude, balloonText, mapId, zoom, markerLng, markerLat, markerText) 
    {
    this.longitude = longitude;
    this.latitude = latitude;
    this.balloonText = balloonText;
    this.mapId = mapId;
    this.zoom = zoom;
    this.markerLng = markerLng;
    this.markerLat = markerLat;
    this.markerText = markerText;
    }
    
    var objectArrayIndex = 0;
    var myObjectArray = new Array();
    
   //adds map values to map array for one marker on a map only
    function setMapObject(longitude,latitude, balloonText,mapId, zoom) 
    {
       myObjectArray[objectArrayIndex++] = new myMapObject(longitude,latitude, balloonText, mapId, zoom, null, null, '');
    }
 
    //used to add more than one marker to a map array
    function setMarkerObject(longitude,latitude, balloonText,mapId, zoom, markerLng, markerLat, markerText) 
    {
       myObjectArray[objectArrayIndex++] = new myMapObject(longitude,latitude, balloonText,mapId, zoom, markerLng, markerLat, markerText);
    }
       
    //loops through array using values to display Google maps
    function showObjectArray(object, length) 
    {
        for (var i=0; i<length; i++) 
        {
        displayMap(object[i].mapId, object[i].longitude, object[i].latitude, object[i].balloonText, object[i].zoom, object[i].markerLng, object[i].markerLat, object[i].markerText);
        }
    }
   
     
    // function provided by Google to display maps 
    function displayMap(sMap, iLongitude, iLatitude, sText, iZoom, iMarkerLng, iMarkerLat, sMarkerText) 
    {
      if (GBrowserIsCompatible()) 
      {
        var map = new GMap2(document.getElementById(sMap));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());

        map.setCenter(new GLatLng(iLatitude, iLongitude, false), iZoom);
        map.addOverlay(createMarker(new GLatLng(iLatitude, iLongitude, false),"<strong>" + sText + "</strong>"));
        if(iMarkerLng != null)
        {
        map.addOverlay(createMarker(new GLatLng(iMarkerLat, iMarkerLng, false), "<strong>" + sMarkerText + "</strong>"));
       }
      }
    }
    
    function createMarker(point, blurb) 
    {
          var marker = new GMarker(point);
          GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(blurb);
      });
      return marker;
}





$(document).ready(function() {



    $("#demo div.item").show();

    /*
    tabbed navigation uses our jquery.scrollable tool, see:

			http://flowplayer.org/tools/scrollable.html
    */
    $(document).ready(function() {
        $("#s1").scrollable(
        {
            items: '.footages',
            prev: 'a.prev1',
            next: 'a.next1',
            size: 4

        });
    });

    $(document).ready(function() {
        $("#s2").scrollable(
        {
            items: '.footages',
            prev: 'a.prev2',
            next: 'a.next2',
            size: 4

        });
    });

    $(document).ready(function() {
        $("#s3").scrollable(
        {
            items: '.footages',
            prev: 'a.prev3',
            next: 'a.next3',
            size: 4

        });
    });
    $(document).ready(function() {
        $("#s4").scrollable(
        {
            items: '.footages',
            prev: 'a.prev4',
            next: 'a.next4',
            size: 4

        });
    });


    $(document).ready(function() {
        $("#tab_panes").scrollable({
            items: '#items',
            size: 1,
            clickable: false,
            //activeClass: 'active'
            //keyboard: false,

            onBeforeSeek: function(e, i) {
                //alert("Triggered onBeforeSeek event");
                if (typeof $f == 'function') { $f().unload(); }
                this.getItems().show();
                //alert("i = " + i);
                //alert(player.done);
                /*
                if (i == 1 && !player.done) {
                    //alert("In the loop!!!")
                    player.controls("homeControls", { duration: 25 });
                    player.done = true;
                }
                */
            }

        }).navigator({ navi: '#tabs', naviItem: 'a' });
    });

    // horizontal scrollables. each one is circular and has its own navigator instance
    //var horizontal = $(".scrollable").scrollable({size: 1}).circular().navigator(".navi");


    // when page loads setup keyboard focus on the first horzontal scrollable
    //horizontal.eq(0).scrollable().focus();
    //{{{ the player

    // just the player without specialities
   
});



