// Initialise items that may be on many pages
$(document).ready(function() {
// Add links to footer and subnav
$('div.footer-legal ul').html('\
Domain Name Registration\
Web Hosting\
Sitemap\
Terms & Conditions\
Privacy Policy\
Disclaimer\
Report a Bug\
Manage Subscriptions\
');
$('ul.subnav').html('\
Why Netregistry?\
About Us\
Careers\
Blog\
News\
Media\
Contact Us\
Login\
Support Centre\
');
// Start banners rotating
startBanner();
// Apply jQuery UI tabs to .tabs
if ($('.tabs').length) {
$('.tabs').tabs({
show: function(event, ui) {$('a', this).blur();},
load: function(event, ui) { }
});
}
// Product page setup
// Hide div below h3.openheader
$('h3.openheader+div').hide();
$('h3.openheader,h3.expandable').click(function() {
$(this).toggleClass('openheader expandable');
$(this).next('div').slideToggle();
});
// Setup links to /forms/* to load_form on click
$('a[href^="/forms/"]').click(function(e) {
e.preventDefault();
load_form(e);
});
// Setup links to /resources/video/* to load_video on click
$('a[href^="/resources/video/"]').click(function(e) {
e.preventDefault();
load_video(e);
});
// Setup anchors to /files/ to open in another window/tab
$('a[href^="/files/"]').attr('target', '_blank');
// Setup anchors to external hrefs to open in another window/tab
$('a:not([href*='+document.location.host+'])[href^=http]').attr('target', '_blank')
// Setup tooltip popups on techspecs
$('.question_mark').hover(
function () {
var posn = $(this).position();
var tooltip = $(this).siblings('div.tooltip');
var tooltip_top = posn.top - $(tooltip).height();
var tooltip_left = posn.left - $(tooltip).width();
$(tooltip).css({'top': tooltip_top, 'left': tooltip_left}).fadeIn('fast');
},
function () {
$(this).siblings('div.tooltip').hide();
}
);
// Dropdown controls
$('.mainnav li').hover(
function () {
$('ul', this).show();
},
function () {
$('ul', this).hide();
}
);
});
// Popup functions
function get_popup() {
// Creates a modal popup for forms/videos
popup = $('div#popup');
if (popup.length == 0) {
$('body').append('');
popup = $('div#popup');
}
popup.dialog({
draggable: false,
modal: true,
resizable: false,
width: 440
});
return popup;
}
// Form functions
function load_form(e) {
// AJAX loads the form into div#form (created if not in DOM)
// Triggered by click event e
popup = get_popup();
// Load form via AJAX
$.ajax({
url: e.currentTarget.href,
type: 'GET',
success: function(data) {
popup.html(data);
// Setup form submission via AJAX
popup.find('form').submit(function(e) {
e.preventDefault();
submit_form(e);
});
}
});
}
function submit_form(e) {
// Submits form over AJAX
// Triggered by form submit event e
form = $(e.currentTarget);
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(),
success: function(data) {
popup = get_popup();
popup.html(data);
// If form submission returned a new form (eg. due to errors),
// setup submission on new form
popup.find('form').submit(function(e) {
e.preventDefault();
submit_form(e);
});
}
});
}
// Video functions
function load_video(e) {
// Loads a video into div#player (created if not in DOM)
// Triggered by click event e
var popup = get_popup();
// Load video via AJAX
$.ajax({
// Point to video page, rather than video file
url: e.currentTarget.href,
type: 'GET',
success: function(data) {
popup.html(data);
var title = popup.find('h2').html()
// Initialise flowplayer
popup.find('a[href$=.flv]').flowplayer(media_url+"lib/flowplayer/flowplayer-3.1.5.swf");
var player = $f();
// Set the video to stop on dialog close
popup.bind('dialogclose', function(event, ui) {
var time = Math.floor(player.getTime());
_gaq.push(['_trackEvent', 'Videos', 'Play Time', title, time]);
player.stop();
});
player.onStart(function() {
_gaq.push(['_trackEvent', 'Videos', 'Play', title]);
});
/* Apparently the onStop event is buggy atm.
player.onStop(function() {
var time = Math.floor(player.getTime());
_gaq.push(['_trackEvent', 'Videos', 'Play Time', title, time]);
});
*/
player.onFinish(function() {
_gaq.push(['_trackEvent', 'Videos', 'Completed', title]);
});
}
});
}
// Banner functions
function startBanner() {
// Setup click-to-stop banner
$('#featured li').live('click',function(){
shiftBanner(this, true);
$('a', this).blur();
return false;
});
// Setup banner rotation
featuredBanner = setTimeout(function(){
if ($("#featured_nav li.selected + li").length > 0) {
shiftBanner($("#featured_nav li.selected + li"));
} else {
shiftBanner($("#featured_nav li:first"));
}
startBanner();
}, 8000);
}
function shiftBanner(e,stopBanner) {
// Rotate banner
if ($(e).is(':not(.selected)')) {
var fiNum = $(e).index();
// If featured_item_x starts has no 0, add 1 to the index
if ($('#featured_item_0').length == 0) {
fiNum++;
}
$('#featured li').removeClass('selected');
$(e).addClass('selected');
$('#featured .featured_item').fadeOut('slow');
$('#featured_item_'+(fiNum)).fadeIn('slow');
}
if (stopBanner) clearTimeout(featuredBanner);
}