$(document).ready(function(){
	// Change home page banner
	$('div.featured_content div.banners').show();
	$('div.featured_content div.banners').css({
		'overflow': 'hidden'											    
	});
	$('div.featured_content div.banners ul li').css({
		'left': '0',
		'position': 'absolute',
		'top': '0'														    
	});
	jQuery.fn.change_banner = function($banner_number){
		$('div.featured_content ul.banners li').removeClass('selected');
		$('div.featured_content ul.banners li#banner_button_'+$banner_number).addClass('selected');
		$('div.featured_content ul.banners li img').attr({src: '/wp-content/themes/petrol/images/buttons/banner_off.png'});
		$('div.featured_content ul.banners li#banner_button_'+$banner_number+' img').attr({src: '/wp-content/themes/petrol/images/buttons/banner_on.png'});
		$('div.featured_content div.banners li').fadeOut(500);
		$('div.featured_content div.banners li#banner_'+$banner_number).fadeIn(500);
	};
	$('div.featured_content div.controls').show();
	$('div.featured_content div.banners li').hide();
	$('div.featured_content div.banners li#banner_1').show();
	$('div.featured_content ul.banners li#banner_button_1').click(function(){
		$(document).change_banner('1');
		$(document).stopTime('cycle_banners');
		return false;
	});
	$('div.featured_content ul.banners li#banner_button_2').click(function(){
		$(document).change_banner('2');
		$(document).stopTime('cycle_banners');
		return false;
	});
	$('div.featured_content ul.banners li#banner_button_3').click(function(){
		$(document).change_banner('3');
		$(document).stopTime('cycle_banners');
		return false;
	});
	$('div.featured_content ul.banners li#banner_button_4').click(function(){
		$(document).change_banner('4');
		$(document).stopTime('cycle_banners');
		return false;
	});
	$('div.featured_content ul.banners li#banner_button_5').click(function(){
		$(document).change_banner('5');
		$(document).stopTime('cycle_banners');
		return false;
	});
	$('div.featured_content ul.banners li#banner_button_6').click(function(){
		$(document).change_banner('6');
		$(document).stopTime('cycle_banners');
		return false;
	});
	$('div.featured_content ul.banners li#banner_button_7').click(function(){
		$(document).change_banner('7');
		$(document).stopTime('cycle_banners');
		return false;
	});
	$('div.featured_content ul.banners li#banner_button_8').click(function(){
		$(document).change_banner('8');
		$(document).stopTime('cycle_banners');
		return false;
	});
	$('div.featured_content ul.banners li#banner_button_9').click(function(){
		$(document).change_banner('9');
		$(document).stopTime('cycle_banners');
		return false;
	});
	$('div.featured_content ul.banners li#banner_button_10').click(function(){
		$(document).change_banner('10');
		$(document).stopTime('cycle_banners');
		return false;
	});
	$test = 2;
	$(document).everyTime(5000, 'cycle_banners', function(){
		$(this).change_banner($test);
		$test2 = $test+1;
		if ( $('div.featured_content ul.banners li#banner_button_'+$test2).length != 0 ) {
			$test++
		}
		else {
			$test = 1;
		}
	});
	// Change number of posts on home page
	var original_height = $('div.content_overview_features ul.items').height();
	$('div.content_overview_features ul.items').css({
		'height': '310px'						   
	});
	$('div.content_overview_features img.more').toggle(function(){
		$('div.content_overview_features ul.items').animate({
			'height': original_height
		});
		$('div.content_overview_features img.more').attr('src', '/wp-content/themes/petrol/images/buttons/home_page_more_selected.png');
	},
	function(){
		$('div.content_overview_features ul.items').animate({
			'height': '310px'
		});
		$('div.content_overview_features img.more').attr('src', '/wp-content/themes/petrol/images/buttons/home_page_more.png');
		return false;
	});
	var original_height_2 = $('div.content_overview_news ul.items').height();
	$('div.content_overview_news ul.items').css({
		'height': '310px'
	});
	$('div.content_overview_news img.more').toggle(function(){
		$('div.content_overview_news ul.items').animate({
			'height': original_height_2
		});
		$('div.content_overview_news img.more').attr('src', '/wp-content/themes/petrol/images/buttons/home_page_more_selected.png');
	},
	function(){
		$('div.content_overview_news ul.items').animate({
			'height': '310px'
		});
		$('div.content_overview_news img.more').attr('src', '/wp-content/themes/petrol/images/buttons/home_page_more.png');
		return false;
	});
	// Clear field value when clicked
	$('.has_default_value').focus(function(){
		if ( $(this).val() == $(this).attr('title') ) { 
			$(this).val('');
		}
	});
	$('.has_default_value').blur(function(){
		if ( $(this).val() == '' ) {
			$(this).val($(this).attr('title'));
		}
	});
	// Colorbox
	$('div.gallery a').colorbox({
		current: "{current} of {total}",
		initialHeight: '150px',
		initialWidth: '150px',
		maxHeight: '90%',
		maxWidth: '90%',
		opacity: 0.50,
		rel: 'colorbox-images',
		speed: 250,
		transition: "elastic"
	});
	$('div.content_box img.aligncenter, div.content_box img.alignleft, div.content_box img.alignnone, div.content_box img.alignright').parents('a').colorbox({
		current: "{current} of {total}",
		initialHeight: '150px',
		initialWidth: '150px',
		maxHeight: '90%',
		maxWidth: '90%',
		opacity: 0.50,
		speed: 250,
		transition: "elastic"
	});
	// Cycling header ads
	$('ul.top_advertisement li:last').addClass('selected');
	$('ul.top_advertisement li').not('li.selected').hide();
	$(document).everyTime(7000, function(){
		$('ul.top_advertisement li.selected').oneTime(0, function(){
			if ( $(this).prev('li').length != 0 ) {
				$(this).fadeOut(500);
				$(this).prev('li').fadeIn(500);
				$(this).prev('li').addClass('selected');
				$(this).removeClass('selected');
			}
			else {
				$(this).fadeOut(500);
				$('ul.top_advertisement li:last').fadeIn(500);
				$('ul.top_advertisement li:last').addClass('selected');
				$(this).removeClass('selected');
			}
		});
	});
	// Open link in new window
	$('a.new_instance').click(function(){
		window.open(this.href);
		return false;
	});
	// Remove focus outline on click
	$('a').mousedown(function(){
		this.blur();
		this.hideFocus = true;
		this.style.outline = 'none';
	});
	// Rollovers
	$('img.rollover, input.rollover').hover(function(){
		$(this).attr('src', $(this).attr('src').replace(/\_off\./gi, '_on\.'));
	},
	function(){
		$(this).attr('src', $(this).attr('src').replace(/\_on\./gi, '_off\.'));
	});
	$('img.rollover, input.rollover').each(function(){
		var rollover_image = $(this).attr('src').replace(/\_off\./gi, '_on\.');
		$('<img>').attr('src', rollover_image);
	});
	// Show hover effects for list items in IE6
	$('div.main_area_home_page div.content div.content_overview ul.items li, div.main_area_standard_page div.content ul.section_items li').hover(function(){
		$(this).addClass('hover');
	},
	function(){
		$(this).removeClass('hover');
	});
});
