// Where to get images:
var cdn_path = 'http://bar.pornhub.com/images/';

// Identify current site:
var phub = /pornhub/i.exec(location.hostname);
var xtub = /xtube/i.exec(location.hostname);
var tub8 = /tube8/i.exec(location.hostname);
var wire = /spankwire/i.exec(location.hostname);
var keez = /keezmovies/i.exec(location.hostname);
var extt = /extremetube/i.exec(location.hostname);
var peep = /(blog\.pornhub|peeperz)/i.exec(location.hostname);
var shop = /store/i.exec(location.hostname);
var bash = /videobash/i.exec(location.hostname);

jQuery(window).ready( function(e) {
	// Build bar:
	jQuery('body').prepend('<div id="ph_net_bar" style="display:none;"></div>');
	jQuery('#ph_net_bar').html('<div id="ph_net_container"></div>');
	jQuery('#ph_net_container').append('<div class="ph_net_links" id="ph_net_logo"></div><div class="ph_net_split"></div>');
	jQuery('#ph_net_container').append('<a class="ph_net_links" id="ph_net_phub" target="_parent" href="http://www.pornhub.com?">PornHub</a><div class="ph_net_split"></div>');
	jQuery('#ph_net_container').append('<a class="ph_net_links" id="ph_net_tub8" target="_parent" href="http://www.tube8.com#">Tube8</a><div class="ph_net_split"></div>');
	jQuery('#ph_net_container').append('<a class="ph_net_links" id="ph_net_wire" target="_parent" href="http://www.spankwire.com?">SpankWire</a><div class="ph_net_split"></div>');
	jQuery('#ph_net_container').append('<a class="ph_net_links" id="ph_net_keez" target="_parent" href="http://www.keezmovies.com?">KeezMovies</a><div class="ph_net_split"></div>');
	//jQuery('#ph_net_container').append('<a class="ph_net_links" id="ph_net_xtub" target="_parent" href="http://www.xtube.com/?splash=false&sex_type=S&gender=M&">XTube</a><div class="ph_net_split"></div>');
	jQuery('#ph_net_container').append('<a class="ph_net_links" id="ph_net_extt" target="_parent" href="http://www.extremetube.com?">ExtremeTube</a><div class="ph_net_split"></div>');
	jQuery('#ph_net_container').append('<a class="ph_net_links" id="ph_net_bash" target="_blank" href="http://www.videobash.com?">Viral Videos</a><div class="ph_net_split"></div>');
	jQuery('#ph_net_container').append('<a class="ph_net_links" id="ph_net_peep" target="_parent" href="http://blog.pornhub.com?">Peeperz</a><div class="ph_net_split"></div>');
	jQuery('#ph_net_container').append('<a class="ph_net_links" id="ph_net_shop" target="_blank" href="http://store.pornhub.com?">T-Shirts</a><div class="ph_net_split"></div>');

	// Bar Styles:
	jQuery('.ph_net_links').css({
		'color': '#ddd',
		'height': '26px',
		'line-height': '25px',
		'padding': '0px 12px',
		'float': 'left',
		'font-size': '11px',
		'text-decoration': 'none'
	});
	var links_active = {'background-color': '#333', 'cursor':'default' };
	var links_hover = {'background-color': '#333', 'color': '#ddd'};
	var links_blur = {'background-color': 'transparent','color': '#ddd'};
	jQuery('.ph_net_split').css({
		'background': 'transparent url('+ cdn_path + 'ph_net_split.png) no-repeat -10px 0',
		'float': 'left',
		'width': '1px',
		'height': '27px'
	});
	jQuery('#ph_net_bar').css({
		'position': 'relative',
		'background': 'transparent url('+ cdn_path + 'ph_net_back.png) repeat-x 0 0',
		'width': '100%',
		'height': '27px',
		'margin': '0px',
		'overflow': 'hidden',
		'font-family': 'Arial,Helvetica,sans-serif'
	});
	jQuery('#ph_net_container').css({
		'position': 'relative',
		'margin': '0px auto',
		'text-align': 'center'
	});
	jQuery('#ph_net_logo').css({
		'float': 'left',
		'background': 'transparent url('+ cdn_path + 'ph_net_logo.png) no-repeat 0 0',
		'width': '153px',
		'height': '27px',
		'margin-right': '5px'
	});

	// Add event listeners for anchors & disable on-site:
	if( !phub || peep ) jQuery('#ph_net_phub').click(function(e) { pageTracker._trackEvent('Network-Bar', 'Pornhub-NetworkBar') } );
	else		jQuery('#ph_net_phub').click(function(e) { return false; } );
	if( !tub8 ) jQuery('#ph_net_tub8').click(function(e) { pageTracker._trackEvent('Network-Bar', 'Tube8-NetworkBar') } );
	else		jQuery('#ph_net_tub8').click(function(e) { return false; } );
	if( !wire ) jQuery('#ph_net_wire').click(function(e) { pageTracker._trackEvent('Network-Bar', 'SpankWire-NetworkBar') } );
	else		jQuery('#ph_net_wire').click(function(e) { return false; } );
	if( !keez ) jQuery('#ph_net_keez').click(function(e) { pageTracker._trackEvent('Network-Bar', 'Keez-NetworkBar') } );
	else		jQuery('#ph_net_keez').click(function(e) { return false; } );
	if( !extt ) jQuery('#ph_net_extt').click(function(e) { pageTracker._trackEvent('Network-Bar', 'Extreme-NetworkBar') } );
	else		jQuery('#ph_net_extt').click(function(e) { return false; } );
	if( !peep ) jQuery('#ph_net_peep').click(function(e) { pageTracker._trackEvent('Network-Bar', 'Peeperz-NetworkBar') } );
	else		jQuery('#ph_net_peep').click(function(e) { return false; } );
	if( !xtub ) jQuery('#ph_net_xtub').click(function(e) { pageTracker._trackEvent('Network-Bar', 'XTube-NetworkBar') } );
	else		jQuery('#ph_net_xtub').click(function(e) { return false; } );
	if( !shop ) jQuery('#ph_net_shop').click(function(e) { pageTracker._trackEvent('Network-Bar', 'Store-NetworkBar') } );
	else		jQuery('#ph_net_shop').click(function(e) { return false; } );
	if( !bash ) jQuery('#ph_net_bash').click(function(e) { pageTracker._trackEvent('Network-Bar', 'Videobash-NetworkBar') } );
	else		jQuery('#ph_net_bash').click(function(e) { return false; } );

	// Pornhub Logo not clickable anymore:
	jQuery('#ph_net_logo').click(function(e) { return false; } );
	jQuery('#ph_net_logo').css('cursor','default');

	// Per-site fixes (UTM info, hover/blur, bar elements, page elements):
	if( phub || peep ) { // Pornhub & Peeperz are on the same domain, so some tweaks are required:
		jQuery('a.ph_net_links:not(#ph_net_'+(peep?'peep':'phub')+')').each( function(e) {
			if( jQuery(this).attr('id') != 'ph_net_shop' ) {
				jQuery('#ph_net_shop').attr('href', 'http://store.pornhub.com' );
			}
			jQuery(this).hover(function(e) { jQuery(this).css(links_hover) }, function(e) { jQuery(this).css(links_blur) });
		});
		jQuery('a.ph_net_links:not(#ph_net_shop):not(#ph_net_phub):not(#ph_net_peep)').each( function(e) {
			jQuery(this).attr('href', jQuery(this).attr('href')+'utm_source=pornhub&utm_medium=network-bar&utm_campaign=pornhub-networkbar' );
		});

		jQuery('#ph_net_'+(peep?'peep':'phub')).css(links_active);

		jQuery('#ph_net_container').css('width', '965px');
	} else if( tub8 ) {
		jQuery('a.ph_net_links:not(#ph_net_tub8)').each( function(e) {
			if( jQuery(this).attr('id') != 'ph_net_shop' ) {
				jQuery(this).attr('href', jQuery(this).attr('href')+'utm_source=tube8&utm_medium=network-bar&utm_campaign=tube8-networkbar' );
				jQuery('#ph_net_shop').attr('href', 'http://pornhubstore.spreadshirt.com/tube8-C63781' );
			}
			jQuery(this).hover(function(e) { jQuery(this).css(links_hover) }, function(e) { jQuery(this).css(links_blur) });
		});
		jQuery('#ph_net_tub8').css(links_active);

		jQuery('#ph_net_container').css('width', '990px');
		jQuery('#ph_net_bar').css('z-index','999999');

		jQuery('body').css('background-position','0 27px');
	} else if( wire ) {
		jQuery('a.ph_net_links:not(#ph_net_wire)').each( function(e) {
			if( jQuery(this).attr('id') != 'ph_net_shop' ) {
				jQuery(this).attr('href', jQuery(this).attr('href')+'utm_source=spankwire&utm_medium=network-bar&utm_campaign=spankwire-networkbar' );
				jQuery('#ph_net_shop').attr('href', 'http://store.pornhub.com' );
			}
			jQuery(this).hover(function(e) { jQuery(this).css(links_hover) }, function(e) { jQuery(this).css(links_blur) });
		});
		jQuery('#ph_net_wire').css(links_active);

		jQuery('#ph_net_container').css('width', '970px');
		jQuery('#ph_net_bar').css('z-index','999999');

		jQuery('body').css('background-position','0 27px');
	} else if( keez ) {
		jQuery('a.ph_net_links:not(#ph_net_keez)').each( function(e) {
			if( jQuery(this).attr('id') != 'ph_net_shop' ) {
				jQuery(this).attr('href', jQuery(this).attr('href')+'utm_source=keez&utm_medium=network-bar&utm_campaign=keez-networkbar' );
				jQuery('#ph_net_shop').attr('href', 'http://pornhubstore.spreadshirt.com/keezmovies-C63782' );
			}
			jQuery(this).hover(function(e) { jQuery(this).css(links_hover) }, function(e) { jQuery(this).css(links_blur) });
		});
		jQuery('#ph_net_keez').css(links_active);

		jQuery('#ph_net_container').css('width', '85%');
		jQuery('#ph_net_logo').css('margin-left', '7px');

		jQuery('body').css('background-position','0 27px');
	} else if( extt ) {
		jQuery('a.ph_net_links:not(#ph_net_extt)').each( function(e) {
			if( jQuery(this).attr('id') != 'ph_net_shop' ) {
				jQuery(this).attr('href', jQuery(this).attr('href')+'utm_source=extremetube&utm_medium=network-bar&utm_campaign=extremetube-networkbar' );
				jQuery('#ph_net_shop').attr('href', 'http://pornhubstore.spreadshirt.com/extremetube-C63783' );
			}
			jQuery(this).hover(function(e) { jQuery(this).css(links_hover) }, function(e) { jQuery(this).css(links_blur) });
		});
		jQuery('#ph_net_extt').css(links_active);

		jQuery('#ph_net_container').css({
			'width': '90%',
			'max-width':'88em'
		});

		jQuery('body').css('background-position','0 27px');
	} else if( xtub ) {
		jQuery('a.ph_net_links:not(#ph_net_xtub)').each( function(e) {
			if( jQuery(this).attr('id') != 'ph_net_shop' ) {
				jQuery(this).attr('href', jQuery(this).attr('href')+'utm_source=xtube&utm_medium=network-bar&utm_campaign=xtube-networkbar' );
				jQuery('#ph_net_shop').attr('href', 'http://store.pornhub.com' );
			}
			jQuery(this).hover(function(e) { jQuery(this).css(links_hover) }, function(e) { jQuery(this).css(links_blur) });
		});
		jQuery('#ph_net_xtub').css(links_active);

		jQuery('#ph_net_container').css('width', '1000px');
		jQuery('#ph_net_bar').css('z-index','999999');

		jQuery('body').css('background-position','0 27px');
	} else if( shop ) {
		jQuery('a.ph_net_links:not(#ph_net_phub)').each( function(e) {
			if( jQuery(this).attr('id') != 'ph_net_shop' ) {
				jQuery(this).attr('href', jQuery(this).attr('href')+'utm_source=store&utm_medium=network-bar&utm_campaign=store-networkbar' );
				jQuery('#ph_net_shop').attr('href', 'http://store.pornhub.com' );
			}
			jQuery(this).hover(function(e) { jQuery(this).css(links_hover) }, function(e) { jQuery(this).css(links_blur) });
		});
		jQuery('#ph_net_phub').css(links_active);

		jQuery('#ph_net_container').css('width', '828px');
	} else if( bash ) {
		jQuery('a.ph_net_links:not(#ph_net_bash)').each( function(e) {
			if( jQuery(this).attr('id') != 'ph_net_shop' ) {
				jQuery(this).attr('href', jQuery(this).attr('href')+'utm_source=videobash&utm_medium=network-bar&utm_campaign=videobash-networkbar' );
				jQuery('#ph_net_shop').attr('href', 'http://pornhubstore.spreadshirt.com/videobash-C63783' );
			}
			jQuery(this).hover(function(e) { jQuery(this).css(links_hover) }, function(e) { jQuery(this).css(links_blur) });
		});
		jQuery('#ph_net_bash').css(links_active);

		jQuery('#ph_net_container').css({
			'width': '90%',
			'max-width':'88em'
		});

		jQuery('body').css('background-position','0 27px');
	}
	// Clean up & show:
	jQuery('a.ph_net_links').each( function(e) {
		if( jQuery(this).attr('href').match(/[?&]$/) ) {
		  jQuery(this).attr('href', jQuery(this).attr('href').slice(0,-1) );
		}
	});
	jQuery('#ph_net_bar').show();
});