﻿


jQuery(document).ready(function() {

    //TICKER
    $("ul#news_ticker").liScroll();

    //VALIDATION


	// gmaps

	if(!$("#googlemap_holder").length ==0) {
	  var map = new GMap2(document.getElementById('googlemap_holder'));
	  var centre = new GLatLng(51.507614,-0.107599);
    	  map.setCenter(centre, 13);
	map.addOverlay(new GMarker(centre));
	  map.addControl(new GSmallZoomControl3D);
	}


    //FLASH BANNER VIDEO
    $('#banner_vid_holder').flash({
        src: $('#bannerfilepath').attr('value'),
        width: 960,
        height: 200
    });
    



    //FLASH PROJECT VIDEO
    $('#hero_vid_holder').flash({
        src: $('#videofilepath').attr('value'),
        params: { play: false },
        flashvars: {},
        width: 330,
        height: 200
    });

    //FLASH PROJECT VIDEO BUTTON FUNCTIONS
    $('input#btnPlay').bind('click', function() {
        $('#hero_vid_holder').flash(function() { this.Play(); });
    });
    $('input#btnStop').bind('click', function() {
        $('#hero_vid_holder').flash(function() { this.StopPlay(); })
    });

    //FLASH PROJECT VIDEO BUTTONS 
    $('#hero_vid_holder').bind('mouseenter', function() {
        $('div#flash_button_holder').fadeIn(500);
    }).bind('mouseleave', function() {
        $('div#flash_button_holder').fadeOut(500);
    });








    //COUNTRY PROJECTS LIST
    $('.country_list_arrow').bind('click', function() {
        var countryattr = $(this).attr('id');
        var countryid = countryattr.replace('countryid', '');

        //var anyopenlist = $('.sub_countries_list');
        //anyopenlist.slideUp(500);

        var projectlist = $('#projectlist' + countryid);
        projectlist.slideToggle(500);
    });

    //ALTERNATIVES PROJECTS LIST
    $('.alternatives_list_arrow').bind('click', function() {
        var alternativetattr = $(this).attr('id');
        var alternativeid = alternativetattr.replace('alternativeid', '');

        //var anyopenlist = $('.sub_alternatives_list');
        //anyopenlist.slideUp(500);

        var projectlist = $('#projectlist' + alternativeid);
        projectlist.slideToggle(500);
    });











    //CAROUSEL
    $("ul#ul_gallery").jcarousel({
        vertical: true,
        scroll: 2,
        initCallback: gallery_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });

    //INITCALLBACK - USED TO ASSIGN FUNCTIONALLITY TO DIVS/ANCHORS (called once onload)
    function gallery_initCallback(carousel) {
        $('.jcarousel-control a').bind('click', function() {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text())); return false;
        });
        $('.jcarousel-scroll select').bind('change', function() {
            carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value); return false;
        });
        $('#gallery_next').bind('click', function() {
            carousel.next(); return false;
        });
        $('#gallery_prev').bind('click', function() {
            carousel.prev(); return false;
        });
        //ADD CLICK EVENT TO BUTTONS HERE
        $('.jcarousel-item img').bind('click', function() {
            var filename = $(this).attr('file');
            var section = $(this).attr('section');

            var main_image = $('#gallery_main_img');
            main_image.attr({ src: '/images/' + section + '/large/' + filename });
            main_image.hide().fadeIn(1000);
        });

        //FADE IMAGE IN
        $('.jcarousel-item img').css('display', 'none').fadeIn(2000);

        //SET FIRST IMAGE TO BE DISPLAYED
        var main_img = $('#gallery_main_img');
        var filename = $(".jcarousel-item-1 > img").attr("file");
        var section = $(".jcarousel-item-1 > img").attr("section");
        main_img.attr({ src: '/images/' + section + '/large/' + filename });
    };







});