
$(document).ready(function () {

	sfHover();
	expandable();


	$('#slideshow').cycle({
		fx: 'fade',
		speed: 1500,
		timeout: 7000,
		pager: '#pageSlideNav',
		/* next line of code fixes white-line problem in IE */
		cleartypeNoBg: true,
		pagerAnchorBuilder: function (idx, slide) {
			return '#pageSlideNav li:eq(' + (idx) + ')';
		}
	});

	$.fn.cycle.updateActivePagerLink = function (pager, currSlideIndex) {
		console.log(pager, currSlideIndex);
		$(pager).find('li').removeClass('activeLI').filter('li:eq(' + currSlideIndex + ')').addClass('activeLI');
	};

	/*	
	$('#sliderNav li a').click(function(e) {
	e.preventDefault();
	$('#slideshow').cycle('pause'); 
	});
	*/

});

/* =================================================================== */
// for suckerfish dhtml menus
// dependencies: jQuery
sfHover = function () {
	$("#navLevelOne li, #countryDropdown").each(function () {
		$(this).hover(function () {
			$(this).addClass('sfhover');
		}, function () {
			$(this).removeClass('sfhover');
		});
	});
};
/* =================================================================== */

/* =================================================================== */
// Expand/Collapse functionality
// dependencies: jQuery
function expandable() {
	var listItems = $('.expandable');
	listItems.children('.expandable-content').hide();
	$('.backToTop', listItems).hide();

	var listLinks = $('h2 a', listItems).click(function (e) {
		if (!$(this).hasClass("link")) {
			e.preventDefault();
			if ($(this).parents('.expandable').children('.expandable-content').length != 0) {
				toggleList($(this).parents('.expandable'));
			}
		}
	});

	for (var x = listItems.length - 1, len = 0; x >= len; x--) {
		if ($(listItems[x]).children('.expandable-content').length != 0) {
			$(listItems[x]).addClass('closed');
		} else {
			$(listItems[x]).addClass('empty');
		}
	}

	function toggleList(parent) {
		if (parent.hasClass('closed')) {
			parent.children('.expandable-content').show();
			parent.removeClass('closed');
			parent.addClass('opened');
		} else {
			parent.children('.expandable-content').hide();
			parent.removeClass('opened');
			parent.addClass('closed');
		}
	}
	if (window.location.hash) {
		$(window.location.hash).parent().siblings("div").toggle();
		$(window.location.hash).addClass("opened");
		$(window.location.hash).removeClass("closed");
		$(window.location.hash).children('.expandable-content').show();
		$('html, body').animate({scrollTop: $(window.location.hash).offset().top}, 100);
	}
};
/* =================================================================== */

/* =================================================================== */
// Links handling
// dependencies: jQuery
function anchors() {
	var externalLinks = $("a[rel=external]");

	externalLinks.click(function (e) {
		e.preventDefault();
		openWin(this, "");
	}); //*/

	function openWin(o, params) {
		window.open(o.href, "newwin", "" + params + "");
		return false;
	}
};
/* =================================================================== */

/* =================================================================== */
// use this to automatically clear a text box of it's default value
// if nothing is typed in the box, the script will put the default value back
// useful on sites where search boxes don't have a seperate label
// you can use it for more than one box per page using the txtBoxes array
txtBoxClear = {
	txtBoxes: ['searchField'],
	init: function () {
		for (i = 0; i < txtBoxClear.txtBoxes.length; i++) {
			var oCurrentTxtBox = document.getElementById(txtBoxClear.txtBoxes[i]);
			if (!oCurrentTxtBox) { continue; }
			oCurrentTxtBox.defaultVal = oCurrentTxtBox.defaultValue;
			txtBoxClear.clearBox(oCurrentTxtBox);
		}
	},
	clearBox: function (txtBox) {
		txtBox.onfocus = function () {
			if (txtBox.value == txtBox.defaultVal) { txtBox.value = ''; }
		};
		txtBox.onblur = function () {
			if (txtBox.value == '') { txtBox.value = txtBox.defaultVal; }
		};
	}
};
/* =================================================================== */

/* =================================================================== */
// old openWin function for opening FLASH demos, bcook added 11/8/2011
// dependencies: none
function openWinBC(url,windowName,w,h)
{
var myNewWin = window.open(url,windowName,'toolbar=no,location=no,directories=no,menubar=no,status=yes,scrollbars=no,resizable=no,width='+w+',height='+h);
myNewWin.focus();
}
/* =================================================================== */


