$(document).ready(function() {

     // 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 a").addClass("selected").show(function() {
    });
    $(".tab_content:first").show();

    $("ul.snippet_tabs li a").click(function() {
        $("ul.snippet_tabs li a").removeClass("selected");
        $(".tab_content").hide();
        var activeTab = $(this).attr("href");


        $(activeTab).fadeIn("fast");

        $("ul.snippet_tabs li a").removeClass("selected");


        $(this).addClass("selected");

        return false;
    });


    $("ul#tabs li a").click(function() {

        $("ul#tabs li a").removeClass("active");
        $(this).addClass("active");
        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");
       
        $(this).addClass("active");
        $(".map").hide();
       
        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").addClass("noBG");

    //    $(".leftSubnavBox li:nth-child(2)").addClass("first");

    $(".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});
    /*
    $.jtabber({
    mainLinkTag: ".testimonials a", // much like a css selector, you must have a 'title' attribute that links to the div id name
    activeLinkClass: "selected", // class that is applied to the tab once it's clicked
    hiddenContentClass: "hide2", // the class of the content you are hiding until the tab is clicked
    showDefaultTab: getDefaultTab(), // 1 will open the first tab, 2 will open the second etc.  null will open nothing by default
    showErrors: true, // true/false - if you want errors to be alerted to you
    effect: 'null', // null, 'slide' or 'fade' - do you want your content to fade in or slide in?
    effectSpeed: 'fast' // 'slow', 'medium' or 'fast' - the speed of the effect
    });
    */
});

/**
 * 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;
}





$(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
$(document).ready(function() {
						   if ($f("player1") != null) {
var player = $f("player1", { src: v.core }, {
        autoPlay: false,

        // this will enable pseudostreaming support
        plugins: {
            //pseudo: { url: v.pseudostreaming },
            controls: {
                playlist: true,
                backgroundColor: '#000000',
                backgroundGradient: 'low'
            }
        }



    }).playlist("div.footages",
		{
		    loop: true



		});
						   }



    //$("#embedPane textarea").html(player.getEmbedCode());

    //}}}


    //{{{ plugins
if ($f("player2") != null) {
    var player = $f("player2", v.core, {
        autoPlay: false,

        plugins: {

            // content plugin, initially hidden
            
            controls: {
                playlist: true,
                backgroundColor: '#000000',
                backgroundGradient: 'low'
            }
        }



    }).playlist("div.footages2", { loop: true });

    //}}}
	}



	if ($f("player3") != null) {
    var player = $f("player3", { src: v.core }, {
        autoPlay: false,

        // this will enable pseudostreaming support
        plugins: {
            //pseudo: { url: v.pseudostreaming },
            controls: {
                playlist: true,
                backgroundColor: '#000000',
                backgroundGradient: 'low'
            }
        }



    }).playlist("div.footages3",
		{
		    loop: true



		});
	}
	if ($f("player4") != null) {
    var player = $f("player4", { src: v.core }, {
        autoPlay: false,

        // this will enable pseudostreaming support
        plugins: {
            //pseudo: { url: v.pseudostreaming },
            controls: {
                playlist: true,
                backgroundColor: '#000000',
                backgroundGradient: 'low'
            }
        }



    }).playlist("div.footages4",
		{
		    loop: true



		});
	}

    //}}}


});
});




