var st_publisher_key = '4b1e6bf0-0e0e-4982-8708-0a80769847b5';

function writeFancyboxAlert(msg)
{
    $.fancybox({ content: "<div id=\"overlay-wrap\" class=\"message\"><div id=\"copy\">" + msg + "</div><div id=\"button-close\"><a href=\"#\" class=\"overlay-close\"><img src=\"/templates/images/button-close-small.png\" alt=\"Close\"></a></div></div>", onComplete: bindOverlay });
}

$(document).ready(

	function () {
	    $(".themed-competition .entercompetitionsubmit").live("click", function (event) {
	        if (validateCompetitionForm(false)) {

	            var form = $(".themed-competition .entercompetitionsubmit").closest("form");
	            $.ajax({
	                type: "POST",
	                url: form.attr("action") + "+msg",
	                data: form.serialize() + "&" + $(this).attr("name") + "=" + $(this).val(),
	                success: function (data) {
	                    writeFancyboxAlert(data);
	                }
	            });
	        }
	        return false;
	    });

	    $(".repeat-survey").live("click", function (e) { e.preventDefault();  $.fancybox({ href: '/my-place/repeat-survey/?overlay=true', onComplete: bindOverlay }); });

	    // Customer FAQ validation messages
	    $(".reg-enquiry #id_matrix .xformvalidator").html("*");

	    // Left hand nav, last li
	    $("#about-side-menu ul li:last").addClass("last");
	    $("#about-side-menu-bottom ul li:last").addClass("last");

	    /* Open up forms in fancy box */
	    $("a.menu-sign-up").fancybox({ 'href': $("a.menu-sign-up").attr('href') + '?overlay=true&ref=' + window.location.href, 'hideOnContentClick': true, 'width': 780, 'height': 690, 'type': 'iframe', onComplete: resizeIframe });
	    $("a.menu-login").fancybox({ 'href': $("a.menu-login").attr('href') + '?overlay=true&ref=' + window.location.href, 'hideOnContentClick': true, 'width': 450, 'height': 580, 'type': 'iframe', onComplete: resizeIframe });
	    $(".overlay-close").click(function (ev) { ev.preventDefault(); parent.$.fancybox.close() });

	    /* Remove input helper text on focus */
	    $('input[id$=UserName]').focus(function () { if ($(this).val() == 'Email address') { $(this).val(''); } });
	    $('input[id$=UserName]').blur(function () { if ($(this).val() == '') { $(this).val('Email address'); } });
	    $('input[id$=FirstName]').focus(function () { if ($(this).val() == 'First name') { $(this).val(''); } });
	    $('input[id$=FirstName]').blur(function () { if ($(this).val() == '') { $(this).val('First name'); } });
	    $('input[id$=LastName]').focus(function () { if ($(this).val() == 'Surname') { $(this).val(''); } });
	    $('input[id$=LastName]').blur(function () { if ($(this).val() == '') { $(this).val('Surname'); } });

	    $('input[id$=Password]').hide();
	    $('input#password-fake').focus(function () {
	        $(this).hide();
	        $('input[id$=Password]').show().focus();
	        //if ($(this).val() == 'Password') { $(this).val(''); } 
	    });

	    $('input[id$=Password]').blur(function () {
	        if ($(this).val() == '') {
	            $('input#password-fake').show();
	            $(this).hide();
	        }
	    });

	    $('input[id$=PasswordConfirm]').hide();
	    $('input#password-confirm-fake').focus(function () {
	        $(this).hide();
	        $('input[id$=PasswordConfirm]').show().focus();
	        //if ($(this).val() == 'Password') { $(this).val(''); } 
	    });

	    $('input[id$=PasswordConfirm]').blur(function () {
	        if ($(this).val() == '') {
	            $('input#password-confirm-fake').show();
	            $(this).hide();
	        }
	    });

	    $('input#email_address').hide();
	    $('input#forgotten-email-fake').focus(function () {
	        $(this).hide();
	        $('input#email_address').show().focus();
	        //if ($(this).val() == 'Password') { $(this).val(''); } 
	    });

	    $('input#email_address').blur(function () {
	        if ($(this).val() == '') {
	            $('input#forgotten-email-fake').show();
	            $(this).hide();
	        }
	    });

	    if ($('#home-flash').length) {
	        var so = new SWFObject("/templates/flash/home-top.swf", "flash-home-swf", "731", "346", "6.0.65", "#000000");
	        so.addParam("quality", "high");
	        so.addParam("wmode", "transparent");
	        so.write("home-flash");
	    }

	    $('.recipe-pdf-download').click(function (event) {
	        achieveEventWithoutConfirmation('Print recipe');
	    });

	    $(".add-qs").each(function () { this.href += "?overlay=true"; });

	    $('.overlay').click(function (event) {
	        event.preventDefault();
	        $.fancybox({ href: $(this).attr("href").replace("/nojs.php?call=", "/") + "?overlay=true", onComplete: bindOverlay });
	    });

	    $('a.overlay-iframe').click(function (event) {
	        event.preventDefault();
	        $.fancybox({ 'href': $(this).attr('href') + '?overlay=true', 'hideOnContentClick': true, 'width': 780, 'height': 690, 'type': 'iframe', onComplete: resizeIframe });
	    });

	    $('.new-overlay-login').click(function (event)
	    {
	        event.preventDefault();
	        parent.$("a.menu-login").click();
	    });

	    $('.new-overlay-signup').click(function (event) {
	        event.preventDefault();
	        parent.$("a.menu-sign-up").click();
	    });

	    $('.new-overlay-faq').click(function (event) {
	        event.preventDefault();
	        parent.$("li#sunflower a").click();
	    });

	    $('.overlay-login').click(function (event) {
	        event.preventDefault();
	        l = location.href;
	        l = l.split('#');
	        //$.fancybox({ href: $(this).attr('href') + '?destination=' + l[0] + "&overlay=true", onComplete: bindOverlay });
	        $("a.menu-login").click();
	    });

	    $('.overlay-new').click(function (event) {
	        event.preventDefault();
	        original_href = $(this).attr("href");
	        new_href = original_href.replace("/nojs.php?call=", "/");
	        $.fancybox({ href: original_href.replace("/nojs.php?call=", "/") + "?overlay=true", onComplete: bindOverlay });
	    });

	    /*
	    $( ".overlay-new" ).each( function() {
	    $( this ).click( function( event ) {                
	    event.preventDefault();                
	    original_href = $(this).attr("href");
	    new_href = original_href.replace("/nojs.php?call=","/");
	    $.fancybox({ href: original_href.replace("/nojs.php?call=", "/") + "?overlay=true", onComplete: bindOverlay });
	    } );
	    } );
	    */

	    $('.overlay-games').click(function (event) {
	        event.preventDefault();
	        original_href = $(this).attr("href");
	        new_href = original_href.replace("/nojs.php?call=", "/");
	        l = location.href;
	        l = l.split('#');
	        $.fancybox({ href: original_href.replace("/nojs.php?call=", "/") + '?destination=' + l[0] + "&overlay=true", onComplete: bindOverlay });
	    });

	    $('.overlay-links a').click(function (event) {
	        event.preventDefault();
	        original_href = $(this).attr("href");
	        new_href = original_href.replace("/nojs.php?call=", "/");
	        $.fancybox({ href: original_href.replace("/nojs.php?call=", "/") + "?overlay=true", onComplete: bindOverlay });
	    });

	    $("#wrapper").css("display", "none");

	    $("#wrapper").fadeIn(2000);

	    $("a.transition").click(function (event) {
	        event.preventDefault();
	        linkLocation = this.href;
	        $("#wrapper").fadeOut(1000, redirectPage);
	    });

	    $(".approachable").approach({
	        "opacity": 0.5
	    }, 100);

	    $('.scrollable').jScrollPane();
	    $('.scrollable-new').jScrollPane({
	        scrollbarWidth: 17,
	        scrollbarMargin: 5,
	        wheelSpeed: 18,
	        showArrows: true,
	        arrowSize: 18,
	        animateTo: false,
	        dragMinHeight: 58,
	        dragMaxHeight: 58,
	        animateInterval: 100,
	        animateStep: 3,
	        maintainPosition: false,
	        scrollbarOnLeft: false,
	        reinitialiseOnImageLoad: true,
	        tabIndex: 0,
	        enableKeyboardNavigation: true,
	        animateToInternalLinks: false,
	        topCapHeight: 0,
	        bottomCapHeight: 0,
	        observeHash: true
	    });
	    $('.rounded').corners();
	    $('.rounded-tabs').corners('top 5px');
	    if ($('#flashmenu').length > 0) {
	        var so = new SWFObject("navigation.swf", "flash-menu-swf", "200", "200", "6.0.65", "#336699");
	        so.addParam("quality", "high");
	        so.addParam("wmode", "transparent");
	        so.write("flashmenu");
	    }

	    $("a[title]").qtip({
	        content: {
	            text: false // Use each elements title attribute
	        },
	        position: {
	            target: 'mouse',
	            adjust: { mouse: true }
	        },
	        show: {
	            effect: { type: 'fade', length: '500' }
	        },
	        style: {
	            width: 130,
	            padding: 5,
	            background: '#bc884f',
	            color: 'white',
	            textAlign: 'center',
	            border: {
	                width: 1,
	                radius: 1,
	                color: '#50341e'
	            }
	        }
	    });


	    var loc = location.href;
	    var charged = 0;

	    loc = loc.split('#');

	    if (loc.length > 1 && charged != 1) {
	        if (loc[1]) {
	            $('#' + loc[1]).trigger("click");

	        }
	    }
	    charged = 1;

	    $("#product-finder .categories select:first").change(updateProductsDD);
	    $("#product-finder .submit input:first").click(function () {
	        window.location = window.location + "?productFinderSpotlightPageId=" + $("#product-finder .products select:first").val();
	        return false;
	    });

	    //Remove non-iframe signup click & replace with iframe
	    $(".signup a").unbind("click").click(function (e) {
	        e.preventDefault();
	        $("a.menu-sign-up").click();
	    });

	    //Add tracking
	    addTracking();

	    // Show overlay straight away?
	    if (window.location.hash) {
	        switch (window.location.hash) {
	            case "#login":
	                $("a.menu-login").click();
	                break;
	            case "#sign-up":
	                $("a.menu-sign-up").click();
	                break;
	        }
	    }
	}
);

function createFacebookFrame(d, s, id) { 
    var js, fjs = d.getElementsByTagName(s)[0];
	if (d.getElementById(id)) {
	    var el = d.getElementById(id);
	    var remElement = (el.parentNode).removeChild(el);
    }
	js = d.createElement(s); js.id = id;
	js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
	fjs.parentNode.insertBefore(js, fjs);
	window.fbAsyncInit = function () {
	    FB.Event.subscribe('edge.create', function (response) {
	        _gaq.push(['_trackSocial', 'Facebook', 'Like', response, location.href]);
	    });
	    FB.Event.subscribe('message.send', function (targetUrl) {
	        _gaq.push(['_trackSocial', 'Facebook', 'Send', targetUrl]);
	    });
	};
} 

function resizeIframe() {
    //resize to avoid srollbars - version 1.3.4
    //$("#fancybox-content").css("height", "800px");
    //$("#fancybox-content").css("width", "800px");

    //resize to avoid srollbars - version 1.3.1
    $("#fancybox-inner").css("height", "800px");
    $("#fancybox-inner").css("width", "800px");
}

function redirectPage() {
	window.location = linkLocation;
}

function bindOverlay() 
{
    // Social
    stButtons.makeButtons();

    $('.overlay-close').click(function(event){event.preventDefault(); parent.$.fancybox.close()});
	$('.overlay-close-refresh').click(function(event){event.preventDefault(); window.location.reload();});

    //if ( $("#fb-root").length > 0 ) createFacebookFrame(document, 'script', 'facebook-jssdk');
   
    /*
    $('.overlay').click(function(event){
		event.preventDefault();
		$.fancybox({ href: $(this).attr("href").replace("/nojs.php?call=", "/") + "?overlay=true", onComplete: bindOverlay });
	});    
    
	$('.overlay-new').click(function(event){
			event.preventDefault();
			original_href = $(this).attr("href");
			new_href = original_href.replace("/nojs.php?call=","/");
			$.fancybox({ href: original_href.replace("/nojs.php?call=", "/") + "?overlay=true", onComplete: bindOverlay });
	});
	
	$('.overlay-games').click(function(event){
		event.preventDefault();
		original_href = $(this).attr("href");
		new_href = original_href.replace("/nojs.php?call=","/");
		l = location.href;
		l = l.split('#');
		$.fancybox({ href: original_href.replace("/nojs.php?call=", "/") + '?destination=' + l[0] + "&overlay=true", onComplete: bindOverlay });
	});   
    */
	$('.overlay-login').click(function(event){
			event.preventDefault();
			l = location.href;
			l = l.split('#');
			$.fancybox({ 'href': $("a.menu-login").attr('href') + '?overlay=true&ref=' + window.location.href, 'hideOnContentClick': true, 'width': 450, 'height': 580, 'type': 'iframe', onComplete: resizeIframe });
        });

	$("form.overlayed").submit(function(event){
		event.preventDefault();
		var a = $(this).attr("action");
		var qs = $(this).serialize();
		a = a.replace("/nojs.php?call=", "/") + '?js=1&' + qs + "&overlay=true";
		$.fancybox({href:a,onComplete:bindOverlay});
		return false;
	});
	
	$("form.overlayed-login").submit(function(event){
		event.preventDefault();
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if($('#email_address').val() == '' || $('#email_address').val() == 'Email address' || !filter.test($('#email_address').val())){
			alert('Please enter a valid email address.');
			return false;
		}

		var a = $(this).attr("action");
		var qs = $(this).serialize();

		a = a.replace("/nojs.php?call=","/")+'?js=1&'+qs;
		$.fancybox({href:a,onComplete:bindOverlay});
		return false;
	});
    		
	$('.scrollable').jScrollPane();

	$('.scrollable-new').jScrollPane({
		scrollbarWidth : 17,
		scrollbarMargin : 5,
		wheelSpeed : 18,
		showArrows : true,
		arrowSize : 17,
		animateTo : false,
		dragMinHeight : 58,
		dragMaxHeight : 58,
		animateInterval : 100,
		animateStep: 3,
		maintainPosition: false,
		scrollbarOnLeft: false,
		reinitialiseOnImageLoad: true,
		tabIndex : 0,
		enableKeyboardNavigation: true,
		animateToInternalLinks: false,
		topCapHeight: 0,
		bottomCapHeight: 0,
		observeHash: true});
        $('.rounded').corners();

        $('#product-finder .categories select:first').change(updateProductsDD);
}

function setPreference(which, alerts) {
    callurl = '/Util/ajax/SetPreference.aspx?p='+which;
	$.ajax({
	    url: callurl,
	    success: function (data) {
	        if (alerts) {
	            $.fancybox({ href: "/fun-and-prizes/confirm-alerts/?overlay=true", onComplete: bindOverlay });
	        } else {
	            $.fancybox({ href: "/fun-and-prizes/confirm-preferences/?overlay=true", onComplete: bindOverlay });
	        }
	    },
        error:function (xhr, ajaxOptions, thrownError){                     
            alert(xhr.status);                     
            alert(thrownError);                 
        }    
	});
}



function achieveEventWithUrl(callevent,url){
	achieveEventWithoutConfirmation(callevent);
	window.open(url);
	return false;
}

function achieveEventWithUrlX(callevent,url,samewindow){
	
	achieveEventWithoutConfirmation(callevent);
	callurl = '/includes/ajax/functions.php?call=achieveEvent&p='+callevent;
	$.ajax({
	  url: callurl,
	  success: function(data) {
		if(samewindow){
			window.location = url;
		}else{
			window.open(url);
		}
	  }
	});
}

function achieveEventWithoutConfirmation(callevent){
	callurl = '/includes/ajax/functions.php?call=achieveEvent&p='+callevent;
	$.ajax({
	  url: callurl,
	  success: function(data) {
	  }
    });
}

//used in competition page to simulate textbox integer spinner
function spin(whichId, minValue, maxValue, amount){

	var spinnerVal = parseInt($("#"+whichId).val());

	if(isNaN(spinnerVal))
	{
		spinnerVal = minValue;
	}

	var newVal = spinnerVal + parseInt(amount);	
	if ( newVal >= minValue && newVal <= maxValue ){
			$("#"+whichId).val(newVal);
	}
}

function updateProductsDD()
{
    populateProductsDD($('#product-finder .categories select:first').val());
}

function populateProductsDD(id)
{
    $('#product-finder .products select:first').attr('disabled', 'disabled');
    $('#product-finder .products select:first >option').remove();

    var category;
    for (var i = 0; i < products.length; i++) {
        if (products[i].Id == id) {
            category = products[i];
            break;
        }
    }
    for (var j = 0; j < category.Products.length; j++) {
        $('#product-finder .products select:first').append($('<option></option>').val(category.Products[j].Id).html(category.Products[j].Name));
    }
    $('#product-finder .products select:first').attr('disabled', '');
}

function validateDaysOut(obj)
{  
    var fup = $("input[type='file']:first");
    if (fup.val() == '') {
        alert('Please upload a photo!');
        return false;
    }

    var fileName = fup.val(); 
    var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
    if (ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "PNG" || ext == "png") //find a better script
    {
        _gaq.push(['_trackpageView','/virtual/photo/upload/Image.jpg']);
        var form = $(fup).closest("form");
        form.attr("enctype", "multipart/form-data");
        form.attr("target", "upload_target");
        form[0].submit();
        return false;
    }
    else {
        alert("Image formats allowed are: gif, jpg and png");
        //fup.focus();
        return false;
    }
    return false;
}

function sendLogin(e)
{
    e.preventDefault();

    var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    if ($('#email_address').val() == '' || $('#email_address').val() == 'Email address' || !filter.test($('#email_address').val())) {
        alert('Please enter a valid email address.');
        return false;
    }

    var a = $(this).attr("action");
    var qs = $(this).serialize();

    a = a.replace("/nojs.php?call=", "/") + '?js=1&' + qs;
    $.fancybox({ href: a, onComplete: bindOverlay });
    return false;
}

function redirectLightbox(url) {
    $.fancybox({ href: url, onComplete: bindOverlay });
}

function validateCompetitionForm(obj) {
    formName = $(".leftcol *:not(:has(div, font, strong, h1, h2, h3, h4)):first").text();

    if (!obj) {
        obj = document.getElementById('entercompetitionform');
    }

    if ($("input[title='First Name']", obj).val() == '') {
        alert('Please provide your first name.');
        return false;
    }

    if ($("input[title='Last Name']", obj).val() == '') {
        alert('Please provide your last name.');
        return false;
    }

    var filter = /^[_A-z0-9-]+(\.[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,3})/;
    if ($("input[title='Email']", obj).val() == '' || !filter.test($("input[title='Email']", obj).val())) {
        alert('We would need a valid email address from you.');
        return false;
    }

    if ($("input[title='Postcode First']", obj).val() == '') {
        alert('Please provide a valid postcode.');
        return false;
    }

    if ($("input[title='Postcode Last']", obj).val() == '') {
        alert('Please provide a valid postcode.');
        return false;
    }

    if ($("select[title='DOB Day'] option:selected", obj).val() == 0) {
        alert('Please provide a valid day for your date of birth.');
        return false;
    }

    if ($("select[title='DOB Month'] option:selected", obj).val() == 0) {
        alert('Please provide a valid day for your date of birth.');
        return false;
    }

    if ($("select[title='DOB Year'] option:selected", obj).val() == 0) {
        alert('Please provide a valid day for your date of birth.');
        return false;
    }

    if (!$("input[title='TAndCs']", obj).is(':checked')) {
        alert('You must accept the terms and conditions.');
        return false;
    }

    _gaq.push(['_trackEvent', 'Forms', 'Enter-' + formName, formName]);
    return true;
}

// SetActivity plugin.
(function ($) {
    $.fn.extend({
        setActivity: function (options) {
            return this.each(function () {
                if (options.name && options.event){
                    $(this).bind(options.event, function(){
                        $.ajax({
                            type: 'POST',
                            data: "{'ActivityName':'" + options.name + "'}",
                            url: '/Service.asmx/SetActivity',
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (response) {
                                if (response.d != null) {
                                    $(".SpudShillingTotal").text(response.d);
                                    $("#menu #spuds").html(response.d);
                                }
                            }
                        });
                    });
                }
            });
        }
    });
})(jQuery);

function htmlDecode(str) {
   return decodeURIComponent(str).replace(/&lt;/g, '<').replace(/&gt;/g, '>');

}

//Apply tracking where required
function addTracking() {
    $(".button-signup-outdoor").live("click", function (e) {
        _gaq.push(['_trackEvent', 'Banner', 'Click', 'Collect 10 Spud Shillings when you sign up for more stuff!']);
    });
    $(".entercompetition-submit").live("click", function (e) {
        _gaq.push(['_trackEvent', 'Forms', 'Enter- Enter 3D TV', 'Win a 3D TV']);
    });

    //social
    $('a[href^="http://www.facebook.com/mccainwedges"]').live("click", function (e) {
        _gaq.push(['_trackSocial', 'Facebook', 'View', $(this).attr("href"), location.href]);
    });

    $('.st_twitter_hcount').live("click", function (e) {
        _gaq.push(['_trackSocial', 'Twitter', 'Tweet', $(this).attr("st_url"), location.href]);
        $.ajax({
            type: 'POST',
            data: "{'ActivityName':'sharetwitter'}",
            url: '/Service.asmx/SetActivity',
            contentType: "application/json; charset=utf-8",
            dataType: "json"
        });
        
    });

    $(".recipe-pdf-download").live("click", function (e) {
        recipe = $("#recipe-heading h1").text();
        _gaq.push(['_trackEvent', 'Print', 'Print Recipe - ' + recipe, recipe]);
    });

    $("#id_matrix:has(#cbs) .btn-submit").live("click", function (e) {
        title = $(".content-intro h1").text();
        _gaq.push(['_trackEvent', 'Forms', 'Enter-' + title, title]);
    });

    $("#id_matrix input:checkbox").live("click", function (e) {
        title = $(".content-intro h1").text();
        if (this.Id.indexOf("participate1") >= 0)
            _gaq.push(['_trackEvent', 'Checkbox', 'Tick-future research' + title, 'future research' + title]);
        if (this.Id.indexOf("newsletter1") >= 0)
            _gaq.push(['_trackEvent', 'Checkbox', 'Tick-monthly e-newsletter' + title, 'monthly e-newsletter' + title]);
    });

    $(".register-col-left input[type=image]").live("click", function (e) {
        _gaq.push(['_trackEvent', 'Email', 'Signup', 'Register with us and you can collect Spud Shillings']);
    });
    $(".register-col-left input:checkbox").live("click", function (e) {
        _gaq.push(['_trackEvent', 'Checkbox', 'Tick-Regular emails with great offers', 'Regular emails with great offers']);
    });
    $(".loginform input[type=image]").live("click", function (e) {
        _gaq.push(['_trackEvent', 'Login', 'User login', 'Farm login']);
    });
    $('.competition-accept input:checkbox[id$="receiveupdatesYes"]').live("click", function (e) {
        _gaq.push(['_trackEvent', 'Checkbox', 'Tick - Receive Offers', 'Receive Offers']);
    });

    $('#recipe-side-content a[id$="linkYoutube"]').live("click", function (e) {
        _gaq.push(['_trackEvent', 'Youtube', 'Watch-More-Videos', 'Youtube Channel']);
    });

    //Youtube tracking
    var tag = document.createElement('script');
    tag.src = "http://www.youtube.com/player_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}

var player;
var videoId;
function onYouTubePlayerAPIReady() {
    $('iframe').each(function () {
        if (this.src.match(/youtube.com/gi)) {
            videoId = this.src.replace("http://www.youtube.com/embed/", "").match(/[^?]+/gi)[0];
            player = new YT.Player(this.id, {
                events: {
                    'onStateChange': onPlayerStateChange
                }
            });
        }
    });
}

function onPlayerStateChange(event) {
    if (event.data == YT.PlayerState.PLAYING) {
        if ($("h2#video-title").size > 0)
            _gaq.push(['_trackEvent', 'Videos', 'Play-' + $("h2#video-title").text(), $("h2#video-title").text()]);
        else if ($("#recipe-heading h1").size() > 0)
            _gaq.push(['_trackEvent', 'Videos', 'Play-' + $("#recipe-heading h1").text(), $("#recipe-heading h1").text()]);
        else
            _gaq.push(['_trackEvent', 'Videos', 'Play-' + videoId, videoId]);
    }
}
