$('#nav ul.quotation').addClass('js');

$(document).ready(function() {

	//$('body').css('behavior', 'url("csshover3.htc")');
	$(document).pngFix();

	// logo carousel
	// test for existence, as carousel is not present on all pages
	if (jQuery.isFunction(jQuery.fn.jcarousel)) {
		//alert('JCarousel!!!');
		//alert($('#sidebar').attr('display'));
		//if ($('#sidebar').attr('display') !== undefined) {
			$('#home #bodywrap #logo-carousel').jcarousel({
				wrap: 'circular',
				scroll: 1
			});
		//}
	}

	// popup functionality
	if (jQuery.isFunction(jQuery.fn.popupWindow)) {
		$('a.popup').popupWindow({
			width: 900,
			height: 1000,
			top: 0
		});
	}

	// get <dl> of nav bar quotations to cross-fade at specified interval
	//$('#nav ul.quotation dl').hide();
	//	$('#nav ul.js').show();

	// cycle plugin crossfades all children
	if (jQuery.isFunction(jQuery.fn.cycle)) {
		$('#nav ul.quotation').cycle({
			'timeout':	15000,
			'speed':	1000
		});
	}

	// prominent home page graphic
	$('#home div.graphpanel-description').prepend('<div id="graphpanel-help"><span class="text">Hover your mouse on each panel for more detail.</span></div>');
	$('#index_v4 div.graphpanel-description ul').prepend('<li id="graphpanel-help"><span class="text">Hover your mouse on each panel for more detail.</span></li>');
	$('#index_v5 div#graphpanel-h3').prepend('<h3 id="graphpanel-help"><span class="text">Hover your mouse on each panel below for more detail.</span></h3>');

	$("div.graphpanel-description ol").hide();
	//$("div.graphpanel-description ol").css('height', '1px');
	//$("div.graphpanel-description ol li").hide();
	//$("div.graphpanel-description ol li[id*='graphpanel-description-']").hide();

	// hide/show boilerplate instructions on mouseover
	$("body.home div.graphpanel-summary ol").hover(
		function() {
			//$('#home div.graphpanel-description ul').css('height', '57px');
			$("div.graphpanel-description ol").show();
			$('#index_v5 div.graphpanel-description ol').css('height', '50px');
			$('div.graphpanel-description #graphpanel-help').hide();
			$("#nav, #main, #sidebar").equalizeCols();
		},
		function() {
			$("div.graphpanel-description ol").hide();
			$('div.graphpanel-description #graphpanel-help').show();
			$("#nav, #main, #sidebar").equalizeCols();
		}
	);

	// show expanded description of each graph segment on mouseover
	$("body.home div.graphpanel-summary li a").hover(
		function() {
			$('div.graphpanel-description ol li, #graphpanel-help').hide();
			$(this).css('background-color', '#cbf2f2').css('z-index', '1000').pureOpacity(0.4);			// aqua bg
			var $target_id = $(this).attr('id');
			$target_id		= '#' + $target_id.replace('graphpanel-summary','graphpanel-description');
			$($target_id).show();
			$("#nav, #main, #sidebar").equalizeCols();
		},
		function() {
			var $current_id = $(this).attr('id');
			$current_id		= '#' + $current_id.replace('graphpanel-summary','graphpanel-description');
			//alert($current_id);
			$('div.graphpanel-description ol li, #graphpanel-help').hide();
			$('#index_v5 div.graphpanel-description ol li' + $current_id).show();
			$(this).find('div.pureOpacity-transparent').remove();
			$("#nav, #main, #sidebar").equalizeCols();
		}
	);

	$("body.home div.graphpanel-summary, body.home div.graphpanel-summary li a").equalizeCols();

	// equalise main column heights, then amend appropriate styles
	// this function must run *after* any other resizing function, insertion of dynamic content, etc.
	$("#nav, #main, #sidebar").equalizeCols();
	$('#bodywrap').css('background', 'none');
	$('#nav').css('background-color', '#fff');
	$('#main').css('background-color', '#f9f8f8');
	$('#sidebar').css('background', "url('/images/widgets/bg/ripple.jpg') #f5f9fa 0 100% no-repeat");
	$('#sidebar').css('border-left', '1px solid #c0bfbf');

	// test
	// on bulleted lists in which only some items are linked,
	// 1. append 'more' link with same url
	// 2. change style of original linked text to match unlinked text
	$('a.more').each(function() {
	//$('#roi-solutions-business-value-index_v2 a.more').each(function() {
		var $url = $(this).attr("href");
		//alert($url);
		$(this).parent("li").append(' <span class="more-append" style="padding-left: 2px"><a href="' + $url + '" style="font-size: 12px">More</a></span>');
		//$(this).parent("li").append(' <span class="more-append"><a href="' + $url + '" style="font-size: 10px; text-transform: uppercase">more</a></span>');
		//$(this).parent("li").append(' [ <a href="' + $url + '" style="font-size: 10px; text-transform: uppercase">more</a> ]');
	});
	$('a.more').css({
		'color': 'inherit',
		'cursor': 'default',
		'text-decoration': 'none'
	});

	handle_mouseovers("body.home #client-logos li a[href], #clients #client-logos li a[href], #partners #partner-logos li a[href]", '_colour', '_colour_big');

	// jquery media
	$('.jqmedia a.media').media({
		width:     960,
		height:    620
		// autoplay:  true,
		// src:       'myBetterMovie.mov',
		// attrs:     { attr1:  'attrValue1', attr2:  'attrValue2' },  // object/embed attrs
		// params:    { param1: 'paramValue1', param2: 'paramValue2' }, // object params/embed attrs
		// caption:   false // supress caption text
	});

	// play video
	var $container = $('.swf');

	$container.each(function() {
		var $swffile	= $(this).find('a:first').attr('href');
		var $width		= $(this).css('width');
		var $height		= $(this).css('height');

		$(this).flash({
			swf: 		$swffile,
			width:	$width,	// Default is 320
			height:	$height,	// Default is 180
			params: {
				play: false,
				allowfullscreen: true,
				allowscriptaccess: 'always'
			},
			flashvars: {
				wmode: 'transparent',
				hasVersion: 8,	// optional and temporary
				autostart: false
			}
		});
	});

	$('div.placeholder2').css('z-index', '1000').pureOpacity(0.6);

	var $msg = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur arcu enim, imperdiet sed volutpat vel, aliquam interdum sem. Proin ipsum elit, dignissim a tristique nec, aliquet non urna. Nunc non luctus mauris. Quisque vitae viverra lectus. Donec a dignissim enim. Praesent laoreet tincidunt malesuada. In a dignissim metus. Donec nulla sapien, volutpat ornare consectetur id, facilisis vitae lorem.';
	//display_debug($msg);

});

// $selector will usually be an "a[href]" tag
// function handles mouseovers, mouseouts, preloading of nested <img>s
function handle_mouseovers($selector, $offsrc, $onsrc) {
	// alert('ok');
	$offsrc	= ($offsrc)	? $offsrc	: '_off';
	$onsrc	= ($onsrc)	? $onsrc		: '_on';

	// preload images
	$($selector).each(function() {
		// Set the original src
		rollsrc = $(this).children("img").attr("src");
		rollON = rollsrc.replace($offsrc,$onsrc);
		//rollON = rollsrc.replace('_off', '_on');
		newImg = new Image(); 				// create new image obj
		$(newImg).attr("src", rollON);	// set new obj's src
	});

	$($selector).mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		if (typeof(imgsrc) != 'undefined') {
			// rollover images are larger, therefore width & height must be removed
			$(this).children("img").removeAttr("width").removeAttr("height");
			imgsrcON = imgsrc.replace($offsrc,$onsrc);
			//imgsrcON = imgsrc.replace('_off', '_on');
			$(this).children("img").attr("src", imgsrcON);
		}
	});

	$($selector).mouseout(function(){
		if (typeof(imgsrc) != 'undefined') {
			$(this).children("img").attr("src", imgsrc);
		}
	});

}

function display_debug($message) {
	$("#jquery-debug").remove();
	$('<div id="jquery-debug" style="position: absolute; top: 0; left: 0; z-index: 1000; background-color: #ffa; width: 250px; padding: 4px; text-align: left; font: 11px/1.1 \'Trebuchet MS\';">' + $message + '</div>').prependTo('body');
	//$('<div id="jquery-debug" style="z-index: 1000; background-color: #ffa; width: 250px; padding: 4px; text-align: left; font: 11px/1.1 \'Trebuchet MS\';">' + $message + '</div>').prependTo('#main');
	$('#jquery-debug').pureOpacity(0.8);
	//$('#jquery-debug').opaqueChildren(0.8);
	//$('#jquery-debug div').css('opacity', 0.9);
	//$('#jquery-debug div').css('font-size', '14px');
}

