﻿/////////////////////////////////////////////////////////////////////////////////////////////////
// WALL METHODS
/////////////////////////////////////////////////////////////////////////////////////////////////


function searchSanctuaryWall(searchString) {
    $('#flashWall').get(0).searchWall(searchString);
    return false;
}

function resultsNotFound() {
    alert("No Results matched the search");
}

// Functionality
function searchWall(criteria) {
    swfWall.searchWall(criteria);
}
function updateUploadField(filename, fbid) {

    $('.divImageName > input').val(filename);
    $('.divFaceBookID > input').val(fbid);
}

function FBLike(type, id) {
    u = SiteURL + 'view-the-sanctuary.aspx?Search=Find~' + type + '~' + id;
    t = document.title;
    window.open('http://www.facebook.com/plugins/like.php?href=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t) + '&layout=standard&show_faces=true&width=450&action=like&font=arial&colorscheme=light&height=80', 'sharer', 'toolbar=0, status=0, width=500, height=50'); return false;
}

function FBShare(type, id) {

    u = SiteURL + 'view-the-sanctuary.aspx?Search=Find~' + type + '~' + id;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0, status=0, width=626, height=436'); return false;
}

function FBLike2() {
    u = window.location;
    t = document.title;
    window.open('http://www.facebook.com/plugins/like.php?href=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t) + '&layout=standard&show_faces=true&width=450&action=like&font=arial&colorscheme=light&height=80', 'sharer', 'toolbar=0, status=0, width=500, height=50'); 
    return false;
}




/////////////////////////////////////////////////////////////////////////////////////////////////
// FACEBOOK METHODS
/////////////////////////////////////////////////////////////////////////////////////////////////

var as_swf_name = "flashUploader";

//Initialize Facebook
function fbInit(pAsSwfName, pApi_key, pReceiver) {
    as_swf_name = pAsSwfName;
    FB.init(pApi_key, pReceiver);
}

//JavaScript Connect methods
function login() {
    FB.Connect.requireSession(onLoginHandler);
}

//Event Handlers
function onLoginHandler() {
    flashCallBack("onLogIn");
}

//Method to dispatch an Event to Flash
function flashCallBack(func) {
    if (arguments.length > 1) {
        document[as_swf_name][func](Array.prototype.slice.call(arguments).slice(1)[0]);
    } else {
        document[as_swf_name][func]();
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////
// GENERAL METHODS
/////////////////////////////////////////////////////////////////////////////////////////////////

function CountLeft(field, count, max) {
    // if the length of the string in the input field is greater than the max value, trim it 
    if ($(field).val().length > max) {
        //field.value = field.value.substring();
        $(field).val($(field).val().substring(0, max));
    }
    else {
        // calculate the remaining characters  
        $(count).val((max - $(field).val().length) + ' Characters remaining');
    }
}


function TrackGotoDonations() {
    TrackAnalyticsURL('/donation-click-top-flash-banner.html');
}

function TrackAnalyticsURL(url)
{
    pageTracker._trackPageview(url);
}




function PhotoMountPageProcess(JQueryObject, ClassName) {
    JQueryObject.removeClass(ClassName);
    JQueryObject.wrap('<div class="' + ClassName + '" />');
}

/////////////////////////////////////////////////////////////////////////////////////////////////
// Front Page Video Banner Methods
/////////////////////////////////////////////////////////////////////////////////////////////////

function openFlashLightBox(whichVid) {
    alert("Javascript functioned called from within flash file!\nPassed it the TVC to play: " + whichVid);
}

// Call from Action Script
function sendToJavaScript(whichFrame) {

    //document.getElementById('theFrameID').value = whichFrame;
    switch(whichFrame)
    {
        case 'play vid':
            TrackAnalyticsURL('/flash-video-click.html');
          break;
        case 'video completed':
            break;
        case 'buy brick':
            TrackAnalyticsURL('/donation-click-top-flash-banner.html');
            window.location = "/buy-a-brick.aspx" 
            break;
        case 'bears':
            SwopFrontPageVideoThumb(false);
            break;
        case 'Nick':
            SwopFrontPageVideoThumb(true);
            break;
        default:
      
    }
}

function ChangeVideoBannerView(IsNick) {
    if (IsNick) {
        $('#FlashTopBanner').get(0).sendToActionscript(1);
    }
    else {
        $('#FlashTopBanner').get(0).sendToActionscript(2);
    }
}

function SwopFrontPageVideoThumb(IsNick) {
    if (IsNick) {
        $('DIV.VideoThumbBears').removeClass('VideoThumbBearsHover');
        $('DIV.VideoThumbNick').addClass('VideoThumbNickHover');
    }
    else {
        $('DIV.VideoThumbBears').addClass('VideoThumbBearsHover');
        $('DIV.VideoThumbNick').removeClass('VideoThumbNickHover');
    }
}

function selectAll(control)
{
    control.focus();
    control.select();
    
}


function fieldSubstitution(sender, args)
{
    args.IsValid = true;
}


function copyToClipboard(hyperlink, textcontainer) {
    //alert(textcontainer.text());
    //var clip = new ZeroClipboard.Client();
    //clip.glue(hyperlink);
    //clip.setText(textcontainer.text());
    
	var clip = new ZeroClipboard.Client();
	clip.addEventListener('load', function (client) {
		alert("Flash movie loaded and ready.");
	});

	clip.setHandCursor( true );
	clip.glue( hyperlink, textcontainer);
	alert('Copied to clipboard');
	

}




