
$(document).ready(function() {

	var labelValue = false;
	if (hcw_options.Label != undefined) {
		labelValue = hcw_options.Label;
	} else {
		labelValue = getURLParam(labelParameterName)
	}
	
	if (labelValue) {
	
		// select all the links where the href starts with (or equals) the custom search URL (which is defined in the HTML)
		var $links = $("a[href]").filter(function(i) {
			var pattern = new RegExp('^' + hcw_options.CustomURL, 'i');
			return pattern.test($(this).attr('href'));
		});
		
		
		// add the param to each of the links
		$links.each(function() {
			var href = $(this).attr('href');
			if (href.indexOf('?') > -1) {
				// this already has a query string
				$(this).attr('href', href + '&label=' + labelValue);
			} else {
				// this doesn't have a query string
				$(this).attr('href', href + '?label=' + labelValue);
			}
		});
		
	}
	
});

// this function returns a url parameter's value by name
function getURLParam(paramName) {
	// if the window.location contains the label parameter name
	if (window.location.search.search(paramName+'=') > -1){
		// split the querystring in to an array of parameters
		var queryArray = window.location.search.substr(1, window.location.search.length).split("&");
		// loop over the params and return the right one if we find it
	  for (var i = 0; i < queryArray.length; i++){
			if (escape(unescape(queryArray[i].split("=")[0])) == paramName){
				return queryArray[i].split("=")[1];
			}
	  }
		
		return '';
	}
}


$(window).load(function() {
	$('#slideshow').cycle({
		speed: 2000, 
    timeout: 8000,
		pager: '#slideshow-pagination'
	});
});

