
$(document).ready(function() {
  initDocument();
  
  
  
});
function sendComments(data){
    $.ajax({ 
    type: "POST", 
    url: "/ajax_comments.cfm", 
    data: data,
    success: function(data){
        $("#ajax_comments").html(data);
        $("#ajax_comments").removeClass('loading');
    }
    });
    return false;
}
function sendCommentsAlt(data){
    $.ajax({ 
    type: "POST", 
    url: "/ajax_comments_alt.cfm", 
    data: data,
    success: function(data){
        $("#ajax_comments").html(data);
        $("#ajax_comments").removeClass('loading');
    }
    });
    return false;
}
function sendCommentsAltFr(data){
    $.ajax({ 
    type: "POST", 
    url: "/ajax_comments_alt_fr.cfm", 
    data: data,
    success: function(data){
        $("#ajax_comments").html(data);
        $("#ajax_comments").removeClass('loading');
    }
    });
    return false;
}
function initDocument() {

$('.banner_text .readmore > a').addClass('video');


$(".video").click(function() {

pathArray = String(this.href).split( '/' ); 
host = pathArray[2];


if (host == "www.youtube.com"){
    $.fancybox({
        'padding'       : 0,
        'autoScale'     : false,
        'transitionIn'  : 'none',
        'transitionOut' : 'none',
        'width'         : 640,
        'height'        : 385,
        'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
        'type'          : 'swf',
        'swf'           : {
            'wmode'             : 'transparent',
            'allowfullscreen'   : 'true'
        }
    });
} else {
     $.fancybox({
        'padding'       : 0,
        'autoScale'     : false,
        'transitionIn'  : 'none',
        'transitionOut' : 'none',
        'width'         : 640,
        'height'        : 385,
        'href'          : this.href,
        'type'          : 'iframe',
        'swf'           : {
            'wmode'             : 'transparent',
            'allowfullscreen'   : 'true'
        }
    });

}
return false;
});








	// Attach Google Tracking Event to all PDF links
	$("#contents a[href$='.pdf']").each(function(){
		$(this).click(function(){
			if (typeof(_gaq)!="undefined") {
				_gaq.push(['_trackEvent', 'PDF', 'Download', '', $(this).attr('href')]);
			} 
		});
	});
	
	if (typeof(initPage)=="function") initPage();
    
    setupGoogleTracking();
}

function loadDiv(id,url,data,callback,issearch) {

	var height = $("#"+id).height();
	var overflow = $("#"+id).css('overflow');
	var html = $("#"+id).html();

	if (typeof(issearch)=='undefined') issearch = false;

	if (issearch) {

		$("#"+id).addClass('on').addClass('loading').css('overflow','hidden');
	
		$("#"+id).animate({
			height: '50px'
		}, 500, function() {
			// Animation complete.
			$("#"+id).html("<div class='searching'>Searching...</div>");

			$.ajax({
				url: url,
				type: "POST",
				data: data,
				cache: false,
				dataType: "html",
				success: function(data, textStatus, XMLHttpRequest){
					$("#"+id).height('auto').html(data).removeClass('loading').attr("onselectstart","").css('overflow',overflow);
					if (typeof(callback)=='function') callback(true);
				},
				error: function(XMLHttpRequest, textStatus, errorThrown){
					//alert('error\n XMLHttpRequest['+XMLHttpRequest+']\n textStatus['+textStatus+']\n errorThrown['+errorThrown+']');
					$("#"+id).html("<a href='' onClick='return loadSignup(data)'>REFRESH</a><br>"+XMLHttpRequest.responseText);
					$("#"+id).height('auto').removeClass('loading').attr("onselectstart","");
					if (typeof(callback)=='function') callback(false);
				}
			});

		});


	} else {

		$("#"+id).addClass('on').addClass('loading').height(height).html('');
		$("#"+id).append("<div class='oldhtml'>" + html + '</div>');
		$("#"+id).attr("onselectstart","return false;");
	
		$("#"+id+' .oldhtml').animate({
			opacity: 0.20
		}, 500, function() {
			// Animation complete.
		});
	
		$.ajax({
			url: url,
			type: "POST",
			data: data,
			cache: false,
			dataType: "html",
			success: function(data, textStatus, XMLHttpRequest){
				$("#"+id).html(data);
				$("#"+id).height('auto').removeClass('loading').attr("onselectstart","");
				if (typeof(callback)=='function') callback(true);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				//alert('error\n XMLHttpRequest['+XMLHttpRequest+']\n textStatus['+textStatus+']\n errorThrown['+errorThrown+']');
				$("#"+id).html("<a href='' onClick='return loadSignup(data)'>REFRESH</a><br>"+XMLHttpRequest.responseText);
				$("#"+id).height('auto').removeClass('loading').attr("onselectstart","");
				if (typeof(callback)=='function') callback(false);
			}
		});
	
	}
	
	return false;
}

function setupGoogleTracking(){
    $('#menuMain #menu_www_recycleme_org_ > a').attr('onclick', "google_Track_Event('External Website', 'Main Menu - About TGLN - (English)', 'http://www.recycleme.org');");
    $('#menuMain #menu_www_recycleme_org_fr_ > a').attr('onclick', "google_Track_Event('External Website', 'Main Menu - About TGLN - (French)', 'http://www.recycleme.org');");
    
    $('#menuMain #menu_www_Serviceontario_ca_beadonor > a').attr('onclick', "google_Track_Event('External Website', 'Main Menu - Donor Registration - (English)', 'http://www.Serviceontario.ca/beadonor');");
    $('#menuMain #menu_www_serviceontario_ca_soyezundonneur > a').attr('onclick', "google_Track_Event('External Website', 'Main Menu - Donor Registration - (French)', 'http://www.serviceontario.ca/soyezundonneur');");
    
    $('#menuMain #menu_www_onelifemanygifts_com_ > a').attr('onclick', "google_Track_Event('External Website', 'Main Menu - Community Relations - (English)', 'http://www.onelifemanygifts.com/');");
    $('#menuMain #menu_fr_communityrelations_ #menu_www_onelifemanygifts_com_ > a').attr('onclick', "google_Track_Event('External Website', 'Main Menu - Community Relations - (French)', 'http://www.onelifemanygifts.com/');");
    
    $(".margin_ad a[href='http://www.Serviceontario.ca/beadonor']").attr('onclick', "google_Track_Event('External Website', 'Side Bar (English)', 'http://www.Serviceontario.ca/beadonor');")
    $(".margin_ad a[href='http://www.serviceontario.ca/soyezundonneur']").attr('onclick', "google_Track_Event('External Website', 'Side Bar (French)', 'http://www.serviceontario.ca/soyezundonneur');")

    $(".margin_ad a[href='http://www.recycleme.org/']").attr('onclick', "google_Track_Event('External Website', 'Side Bar (English)', 'http://www.recycleme.org/');");
    $(".margin_ad a[href='http://www.recycleme.org/fr/']").attr('onclick', "google_Track_Event('External Website', 'Side Bar (French)', 'http://www.recycleme.org/fr/');");
    
    $(".margin_ad a[href='http://www.onelifemanygifts.com/']").attr('onclick', "google_Track_Event('External Website', 'Side Bar (English)', 'http://www.onelifemanygifts.com/');");
    $(".margin_ad a[href='http://www.onelifemanygifts.com/fr/']").attr('onclick', "google_Track_Event('External Website', 'Side Bar (French)', 'http://www.onelifemanygifts.com/fr/');");

}

function google_Track_Event(category, action, label){

    _gaq.push(['_trackEvent', category, action, label]);

}



