$(document).ready(function(){

    $('div.tommahawk-watcher a').click(function () {

        var div = $(this).parent();

        var youtubeid = div.attr("youtubeid") || div.attr("data-youtubeid");

        var url = "http://www.youtube.com/v/" + youtubeid + "&autoplay=1&rel=0&showinfo=0";

        var swfid = "swfembed" + div.attr("id");

        div.html('<div id="' + swfid + '"></div>');

        swfobject.embedSWF(url, swfid, div.width(), div.height(), "8");

        return false;
    });

	//Links to specified time in video
	$('.time_link').click(function () {
		var div = $(this).attr("data-which-vid");
	        var youtubeid = $('#' + div + '').attr("youtubeid") || $('#' + div + '').attr("data-youtubeid");
		var youtubeTime = $(this).attr("data-time");
	        var url = "http://www.youtube.com/v/" + youtubeid + "&autoplay=1&rel=0&showinfo=0&start=" + youtubeTime;
	        var swfid = "swfembed" + $('#' + div + '').attr("id");
	        $('#' + div + '').html('<div id="' + swfid + '"></div>');
	        swfobject.embedSWF(url, swfid, $('#' + div + '').width(), $('#' + div + '').height(), "8");
	        return false;
	});


    if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/Android/i)) {

        $('div.tommahawk-watcher').each(function () {

            var div = $(this);
            var url = "http://www.youtube.com/v/" + div.attr("data-youtubeid") + "&autoplay=0&rel=0&showinfo=0";

            div.html('<object width="' + div.width() + '" height="' + div.height() + '"><param name="movie" value="' + url + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + url + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + div.width() + '" height="' + div.height() + '"></embed></object>');

        });
	}

});
