/* Author: */
var vjVideo = (function () {
    var params = {
        allowScriptAccess: "sameDomain",
        allowFullScreen: "true",
        menu: "false",
        base: "/flash/",
        bgColor: "#000000"
    },
    flashVars = {
        url: '', 		// The URL to the video
        previewURL: '', 	// [Optional] The URL to a preview image to load (only use if autoPlay = false)
        autoPlay: true, 			// [Optional] Default: false	- Determines if the video will begin automatically playing (if true, the preview image will NOT be loaded)
        autoHideControls: true, 		// [Optional] Default: true		- Determines if the controls are automatically hidden when the mouse leaves the player, or is still for several seconds
        colorForeground: "#FFFFFF", 	// [Optional] Default: #FFFFFF	- The foreground color of interface elements
        colorBackground: "#222222", 	// [Optional] Default: #222222	- The background color of interface elements
        colorTheme: "#115059", 		// [Optional] Default: #FFCC00	- The theme color of interface elements
        controls: "scrub,time,duration,volume,quality,fullscreen", // [Optional] Default: scrub,time,duration,volume,fullscreen	- The controls that are shown. Available options: scrub, time, duration, volume, quality, fullscreen
        framing: "touchinside", 		// [Optional] Default: touchinside - The framing of the video. Available options: normal, stretch, touchinside, touchoutside
        volume: 1, 					// [Optional] Default: 1		- The initial volume of the video
        bufferPerc: 0.1, 			// [Optional] Default: 0.1		- The percentage of the video to buffer before it will begin playing (between 0 and 1. If bufferTime is set to a value > 0, this value is NOT used)
        bufferTime: 0, 				// [Optional] Default: 0		- The number of seconds of video to buffer before it will begin playing (this value will override bufferPerc)
        borderRadius: 0, 			// [Optional] Default: 0		- The radius of the border around the video. Use this to add rounded corners to the video.
        borderColor: "#FFFFFF", 		// [Optional] Default: #FFFFFF	- The colour of the border around the video (if borderRadius is 0, this value is not used)
        showSpinner: true			// [Optional] Default: #FFFFFF	- The colour of the border around the video (if borderRadius is 0, this value is not used)
    },
    videos = {};

    return {
        build: function(id, url, preview){
            videos[id] = {
                'id': id,
                'url': url,
                'preview': preview
            }
            this.play(id);
        },
        play: function (id) {
            var vars = flashVars,
                video = videos[id];

            vars.url = video.url;
            vars.previewURL = video.preview;

            swfobject.embedSWF("/flash/vjvideoplayer.swf", "video_" + video.id, "640", "362", "9.0.260.0", false, vars, params, { 'id': "vid_" + id, 'name': "vid_" + id });
        },
        stop: function (id) {
            var ele = 'vid_' + id;
            var parent = $('#' + ele).parent();
            swfobject.removeSWF(ele);
            parent.append('<div id="video_' + id + '"></div>');
            this.play(id);
        }
    }
} ());

$(document).ready(function () {

    Cufon.replace('h1, h2, .template.home h2, .template.other h2,  h3, p.footer-title, p.footer-title-2, .article-type-a dt, .template.other .main-left h5, .template.other h3, p.profile-name, p.offer-name, p.tenant-name, p.q-desc, li.twnAnswer dl dt, .rhs-promos .view-map dl dt, dl.article-precints dt, .feature-property dl dt, dd.rhs-subtitle, .quote-name, .article-generic-a li dd.title-text, .store-list-title, dd.year-flag, .template.home .banner-container .banner-overlay p.banner-txt-3, .template.other .banner-container .banner-overlay p.banner-txt-2, .overlay-1 .popup-title, .overlay-1-content-right ul li dt, .rhs-promos li dl dt, .template.home .main-left .pages-list li p a.btn-home, .template.home .main-inner .main-right a.btn-home', { fontFamily: 'gotham-bold' });

    Cufon.replace('h4, .template.other address, .template.home .banner-container .banner-overlay p.banner-txt-2, .template.other .banner-container .banner-overlay p.banner-txt-1', { fontFamily: 'gotham-medium' });

    Cufon.replace('.template.home .banner-container .banner-overlay p.banner-txt-1, .template.home .banner-container .banner-overlay p.banner-txt-4, .template.other .banner-container .banner-overlay p.banner-txt-3', { fontFamily: 'gotham-book' });

    /* Global Main Menu */
    /*navHover = function() {*/
    $('#main-nav').find('li').hover(function () {
        $(this).find('ul').show();
    }, function () {
        $(this).find('ul').hide();
    });

    $('#main-nav').find('ul').hover(function () {
        $(this).prev('a').addClass('active');
    }, function () {
        $(this).prev('a').removeClass('active');
    });
    /* } */

    /* HOME page banner slideshow */
    $('#slideshow-banner').cycle({
        //fx:     'scrollLeft',
        fx: 'fade',
        speed: 200,
        timeout: 7000,
        pager: '#banner-control',
        slideExpr: 'li',
        sync: 0,
        pause: 1
    });

    /* remove overlay banner text if there no content */
    var bannerTxt = $('.other p.banner-txt-1').text();
    bannerTxt += $('.other p.banner-txt-2').text();
    bannerTxt += $('.other p.banner-txt-3').text();
    if (bannerTxt == "" || bannerTxt == null) {
        $('.other .banner-overlay').hide();
    }

    /* Article slide up & down - Media Centre & Find Us page */

    $('div.main-left').find('.twnQuestion').click(function (e) {
        if ($(this).next('.twnAnswer').is(':visible')) {
            $(this).next('.twnAnswer').slideUp(function () {
                $(this).prev().removeClass('active');
                //$(this).find('.closeDd').remove();
            });
            $(this).find('.twnQuestion-trigger').removeClass('active');
        } else {
            $(this).addClass('active');
            $(this).find('.twnQuestion-trigger').addClass('active');
            $(this).next('.twnAnswer').slideDown(function () {

            });
        }
        e.preventDefault();
    });

    /* Article TABBING switching TENANT DIRECTORY page */
    /*
    $('ul.tabbing-ctrl li a.commercial').click(function(e){
    if (!$(this).hasClass('active')){
    $(this).addClass('active');
    $('#commercial-content').show();
    $('ul.tabbing-ctrl li a.retail').removeClass('active');
    $('#retail-content').hide();
    }
    e.preventDefault();
    });
	
    $('ul.tabbing-ctrl li a.retail').click(function(e){
    if (!$(this).hasClass('active')){
    $(this).addClass('active');
    $('#retail-content').show();
    $('ul.tabbing-ctrl li a.commercial').removeClass('active');
    $('#commercial-content').hide();
    }
    e.preventDefault();
    });
    */
    $('.history-container li:last-child').addClass('last-history');

    /* interactive map - remove <a class="close"> */
    $('#map-sort-trigger').click(function (e) {
        if ($('#map-sort').is(":visible")) {
            $('#map-sort').slideUp('slow');
        } else {
            $('#map-sort').slideDown('slow');
        }
        e.preventDefault();
    });

    /* interactive map - remove <a class="close"> */
    $('#map-sort li a').hover(
		function () {
		    $(this).parent().addClass('hover');
		},
	  	function () {
	  	    $(this).parent().removeClass('hover');
	  	}
	);

    /* Over lay popup */
    $("a[rel]").overlay({
        mask: '#000',
        api: true,
        onClose: function () {
            if ($(this.getTrigger()).is('.video')) {
                var id = $(this.getOverlay()).find('object')[0].id;
                vjVideo.stop(id.replace('vid_', ''));
            }
        }
    });


});

