

/* emg.js.php */
/*
12:25 PM 1/6/2011 - added tokenInit() and toggleClassArray()
3:38 PM 12/13/2010
2:04 PM 10/14/2010
3:52 PM 10/12/2010
/*
Copyright © 2008 Eckx Media Group, LLC. All rights reserved.
Eckx Media Group respects the intellectual property of others, and we ask our users to do the same.
*/
/*<script>*/

var emgInit = function(){
			BrowserDetect.init();			ie6Check();
	//emg link
	$('#emg-link').hide();
	
	if(window.siteInit){
		siteInit();
	}
	
	$('.hide').hide(); //hide all elements with class hide
	
	markupInit();
	setEventHandlers('body'); // set event handlers
};

$(document).ready(emgInit);

//function to run initial function that changes markup
function markupInit(){
	var bodyElement = $('body')[0]; // cant use document.body because error in IE7, no .select
	// confirmInit(bodyElement); moved to setEventHandlers
	externalLinks(bodyElement);
	autoCompleteOff(bodyElement);
	defaultClear(bodyElement);
	
	ieSelectExpand();
}

function setEventHandlers(container){
	// confirm2
	$('a[rel~="confirm"]', container).click(function() {
		//event.preventDefault();
		var url = $(this)[0].href;
		var message = $(this)[0].title;
		var target = $(this)[0].target;
		if (target == '_blank') { // open link in new window
			confirm2(null, message, 'window.open(\'' + url + '\')'); 
		}
		else {
			confirm2(null, message, 'window.location = \'' + url + '\';'); 
		}
		return false;

	});
	
	//focus specified field when max length has been entered, good for phone numbers
	$('input[type="text"].max-length-next').keyup(function(event){
		if(event.keyCode == 9){ //ignore tabs
			return;	
		}
		if(this.value.length == this.maxLength){
			var focusid = classAfter('max-length-next', this.className);
			$('#' + focusid).focus();
		}
	});
	
	// Form address fields
	emgFormAddressFields();
	
	// site specific event handlers
	if (window.setSiteEventHandlers) { 
		setSiteEventHandlers(container);
	}
}

function emgFormAddressFields() {
	// Input names
	var provinceName = 'province';
	var stateName = 'stateid';
	var countryName = 'countryid';
	var zipName = 'zip';
	
	//comment out because auto trigger below should handle it
	//$('.emg-form input[name="' + provinceName + '"], .emg-form input[name^="' + provinceName + '["]').closest('li').hide();
	
	// Account for names and name arrays
	$('.emg-form select[name="' + countryName + '"], .emg-form select[name^="' + countryName + '["]').change(function() {
		// Id strings
		var provinceId = this.id.replace(countryName, provinceName);
		var stateId = this.id.replace(countryName, stateName);
		var zipId = this.id.replace(countryName, zipName);
		
		// Input fields
		var provinceInput = $('#' + provinceId);
		var stateSelect = $('#' + stateId);
		var zipInput = $('#' + zipId);
		
		// Check if state & zip are initially required
		/* why do we need to check this
		var stateIsRequired = stateSelect.hasClass('val_req');
		var zipIsRequired = zipInput.hasClass('val_req');
		*/
		
		// Element containers
		var provinceContainer = $('#' + provinceId + '-container');
		var stateContainer = $('#' + stateId + '-container');
				
		// 1 => United States
		// Require state/zip if they are initially required
		if (this.value == 1) {
			provinceContainer.hide();
			/*
			if (stateIsRequired) {
				stateSelect.addClass('val_req');
			}
			*/
			stateSelect.addClass('val_req'); // if country is US, require state
			
			stateContainer.show();
			
			zipInput.addClass('val_exist zip');
			/*
			if (zipIsRequired) {
				zipInput.addClass('val_req');
			}
			*/
			zipInput.addClass('val_req'); // if country is US, require zip
			
		}
		else {
			stateContainer.hide();
			stateSelect.removeClass('val_req');
			
			provinceContainer.show();
			
			zipInput.removeClass('val_req val_exist zip');
		}
	});
	
	//set based on default value
	var ul = $('.emg-form input[name="' + provinceName + '"], .emg-form input[name^="' + provinceName + '["]').closest('ul.fields');
	var countryField = $('[name="' + countryName + '"], [name^="' + countryName + '["]', ul);
	countryField.trigger('change');
	
}

function classAfter(needle, haystack){
	var classes = haystack.split(' ');
	for(var i = 0; i < classes.length; i++){
		if(classes[i] == needle){
			return classes[i + 1];
		}
	}
}

//Event.observe(window, 'load', emgInit);
//document.observe('dom:loaded', emgInit);

// Show / Hide object
function toggle(obj) {
	alert('Deprecated - use toggleClass with css');
	return;
	
	var el = $(obj);
	el.style.display = (el.style.display != 'block' ? 'block' : 'none' );
	el.blur();
}
function toggle2(obj) {
	alert('Deprecated - use toggleClass with css');
	return;
	
	var el = $(obj);
	el.style.display = (el.style.display != 'block' ? 'block' : 'none' );
	el.blur();
}

function toggleClass(id, className) {
	$('#' + id).toggleClass(className);
	/*
	var el = $(id);
	if (el.hasClassName(className)) {
		el.removeClassName(className);
	}
	else {
		el.addClassName(className);
	}*/
}

function toggleClassArray(ids, className){
	for(var i = 0; i < ids.length; i++){
		toggleClass(ids[i], className);	
	}
}

// Reset form fields
function clearForm(id, skipids) {
	if(!skipids){
		skipids = new Array();
	}
	var form = byId(id);
	for (var i = 0; i < form.length; i++) {
		if(inArray(form[i].id, skipids) || form[i].type == 'submit' || form[i].type == 'button' ){
			continue;
		}
		if(form[i].type == 'checkbox' || form[i].type == 'radio') {
			form[i].checked = false;	
		}
		if(form[i].options){ // drop downs
			form[i].selectedIndex = 0;
		}
		else {
			form[i].value = '';
		}
		
	}
}

// Reset form fieldset fields
function clearFieldset(id) {
	var fieldset = $('#' + id + ' input[type="text"], ' + '#' + id + ' input[type="password"], ' + '#' + id + ' input[type="file"], ' + '#' + id + ' select, ' + '#' + id + ' textarea');
	
	for (var i = 0; i < fieldset.length; i++) {
		clearField(fieldset[i]);
	}
}
// Clear individual field
function clearField (field) {
	if(field.type == 'checkbox' || field.type == 'radio') {
		field.checked = false;	
	}
	else {
		field.value = '';
	}
}

function popUpA(URL) { //allow all features
	day = new Date();
	id = "aboutUS";
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=900,height=400,left = 240,top = 212');");
}

function popUpB(URL) { // disable all features
	day = new Date();
	id = "aboutUS";
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=300,left = 240,top = 212');");
}

function isset(obj){
	if(typeof obj == 'undefined'){
		return false;
	}
	else{
		return true;	
	}
}


function getMousePos(e) {
	var IE = document.all?true:false
	var scrollXY = getScrollXY();
	var mousePos = new Array();
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = e.x;
		tempY = e.y;
	} 
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.clientX;
		tempY = e.clientY;
	}
	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}  
	mousePos['x'] = tempX + scrollXY[0];
	mousePos['y'] = tempY + scrollXY[1];
	return mousePos;
}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getPageDim(){
	/*if(document.all?true:false){ // IE
		if(document.body.clientHeight > document.body.scrollHeight){
			var height = document.body.clientHeight;
			var width = document.body.clientWidth;
		}
		else{
			var height = document.body.scrollHeight;
			var width = document.body.scrollWidth;
		}
	}
	else{
		var height = document.height;
		var width = document.weidth;
	}
	var viewPortHeight = document.viewport.height();
	if(height < viewPortHeight){
		height = viewPortHeight;
	}*/
	return [ $(document).width(), $(document).height() ];
}

function getVisibleDim(){ alert('function getVisibleDim() decremented, use prototype viewport');
	if(!$('getTopLeft-fake-body')){ //generate fake div to get screen size
		var fakeDiv = document.createElement('div');
		fakeDiv.id = 'getTopLeft-fake-body';
		fakeDiv.style.visibility = 'hidden';
		fakeDiv.style.margin = '0';
		fakeDiv.style.padding = '0';
		fakeDiv.style.position = 'absolute';
		fakeDiv.style.top = '0';
		fakeDiv.style.bottom = '0';
		fakeDiv.style.left = '0';
		fakeDiv.style.right = '0';
		fakeDiv.style.width = '100%';
		fakeDiv.style.height = '100%';
		fakeDiv.style.zIndex = '-1';
		document.body.appendChild(fakeDiv);
	}
	
	var fakeDiv = $('getTopLeft-fake-body');
	var width = fakeDiv.getWidth();
	var height = fakeDiv.height();
	return [ width, height ];
}


function alert2(text, dim, alertTime, className){ 
	//check if alert 2 already exist
	
	var i = 0;
	while(byId('alert2_' + i)){
		i++;
	}
	
	var alert2 = document.createElement('div');
	
	alert2.id = 'alert2_' + i;
	alert2.style.visibility = 'hidden';
	document.body.appendChild(alert2);
	
	alert2 = byId('alert2_' + i);
	if (className === undefined) {
		$(alert2).addClass('alert2');
	}
	else {
		$(alert2).addClass(className);	
	}
	
	alert2.innerHTML = text;
	
	if (dim) {
		width = dim[0];
		height = dim[1];
		alert2.style.width = width + 'px';
		alert2.style.height = height + 'px';
	}
	else {
		width = $(alert2).width();
		height = $(alert2).height();
	}
	
	if(isNaN(width) || isNaN(height)){
		alert('Alert2() error, width or height isNaN');	
	}
	
	var xy = getScrollXY();
	var topLeft = getTopLeft(width, height);
	alert2.style.top = topLeft[0]+'%';
	alert2.style.left = topLeft[1]+'%';
	alert2.style.visibility = 'visible';
	if (!alertTime) {
		alertTime = 2000;	
	}
	setTimeout("document.body.removeChild(document.getElementById('alert2_" + i + "'))", alertTime);
}


//return the top left percentage for an absolute centered layer, req 100% body height
function getTopLeft(width, height){
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	var ie = getIEVerNum();
	
	//compensate for scroll
	var xy = getScrollXY();
	
	//get %
	var top = (windowHeight/2 + xy[1] - (height/2)) / windowHeight;
	var left = (windowWidth/2 + xy[0] - (width/2)) / windowWidth;

	if(top < 0){
		top = 0;	
	}
	if(left <0){
		left = 0;	
	}
	
	//compensate for ie 6 usage of %, the entire document not just what u see is 100%
	if(ie == 6){ // ie 6
		var pxHeight = windowHeight * top; //get pixel height
		top = pxHeight/document.body.clientHeight; // get decimal height
	}
	
	top  = Math.round(top * 100); 
	left  = Math.round(left * 100);
			
	return [ top, left ];
}

function money(num){
	var formated = Math.round(num*1000)/1000; //use 1000 for partial cents
	formated = formated.toString();
	if(formated.indexOf('.') == -1){
		formated += '.00';
	}
	else{
		var parts = formated.split('.');
		if(parts[1].length == 1){
			formated += '0';	
		}
	}
	return formated;
}

function urlencode(str) { alert('use encodeURIComponent()');
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}

function urldecode(str) {
	str = str.replace('+', ' ');
	str = unescape(str);
	return str;
}

function htmlentities(html) {
	html = html.replace('<','&lt;');
	html = html.replace('>','&gt;');
	html = html.replace('"','&quot;');
	return html;
} 

function getJs(url){
	if(!inString(url, '?')){
		url += '?';	
	}
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url+'&klioe='+Math.random()*10000;
	document.body.appendChild(jsel);
}

//Get IE Version Number
function getIEVerNum() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}

function confirm2(e, title, yesEval, noEval, yesTitle){
	var yesText = (yesTitle) ? yesTitle : 'Yes';
	var noText = (yesTitle) ? 'Cancel' : 'No';
	
	var delConfirm = document.createElement('div');
	delConfirm.id = 'confirm2';
	document.body.appendChild(delConfirm);
	modal.load();
	modal.content('<p><strong>'+title+'</strong></p><ul class="tools confirm"><li class="yes"><span><a href="#" id="confirm2-yes">'+yesText+'</a></span></li><li class="no"><span><a href="#" id="confirm2-no">'+noText+'</a></span></li></ul>');
	//delConfirm = $('confirm2');
	//delConfirm.addClassName('confirm2');
	//delConfirm.innerHTML = '<div>'+title+'</div><input type="button" id="confirm2_yes" value="Yes"/><br/><input type="button" id="confirm2_no" value="No" />';
	
	//var mousePos = getMousePos(e);
	//delConfirm.style.left=mousePos['x']+'px';
	//delConfirm.style.top=mousePos['y']+'px';
	$('#confirm2-yes')[0].onclick= function(){ 
		//document.body.removeChild($('confirm2'));
		eval(yesEval);
		modal.close();
		return false;
	}
	$('#confirm2-no')[0].onclick= function(){ 
		//document.body.removeChild($('confirm2'));
		eval(noEval); 
		modal.close();
		return false;
	}
}

function checkAll(name, trueFalse){
	var checkBoxes = document.getElementsByName(name);
	var len = checkBoxes.length;
	for(var i=0; i<len; i++){
		checkBoxes[i].checked = trueFalse;
	}
}

function confirmInit(container){
	var anchors = $('a[rel~="confirm"]', container);
	for(var i = 0; i < anchors.length; i++){
		anchors[i].href  = 'javascript:confirm2(null, \'' + anchors[i].title + '\', \'window.location=\\\'' + anchors[i].href + '\\\'\', \'\')';
	}
}

function externalLinks(container) {
	var anchors = $('a[rel~="external"]', container);
	
	for (var i=0; i<anchors.length; i++) {
		anchors[i].target = "_blank";
	}
}

function autoCompleteOff(container){
	var inputs = $('input[class~="autocomplete-off"]', container);
	for (var i=0; i<inputs.length; i++) {
		inputs[i].setAttribute("autocomplete", "off");
	}
}

function defaultClear(container){	
	var inputs = $('[class~="default-clear"]', container);
	
	var defaultClassName = 'default';
	
	
	inputs.focus(function() {
		if(this.value == this.defaultValue){
			this.value = '';
			$(this).removeClass(defaultClassName);
		}
	}).blur(function() {
		if(this.value == ''){
			this.value = this.defaultValue;
			$(this).addClass(defaultClassName);
		}
	});
}

function bookMark(url, title){
	if(document.all?true:false){ // IE
		window.external.AddFavorite(url, title);
	}
	else{
		window.sidebar.addPanel(title, url, '')
	}
}

function ajaxFill(url, containerid, callback){
	alert('depercated, please use EmgAjax.call()');
	return;
	var container = $(containerid);
	if(!container){
		alert('ajaxFill(): '+containerid+' id dosnt exist');
		return;
	}
	container.innerHTML = '<div style="text-align:center"><img src="'+window.CR+'/images/library/loading.gif" /></div>';
	new Ajax.Request(url, { method: 'get', onSuccess: function(ajaxReturn) {
		if(ajaxReturn.responseText == 'died'){
			window.location = window.CR + '/died';
			return;
		}
		container.innerHTML = ajaxReturn.responseText;
		curtain.initLinks(container); //curtain reference
		eval(callback);
	}}); 
}

function ie6Check() {
	if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7) {
		var ie6Notice = document.createElement('div');
		ie6Notice.id = 'ie6-notice';
		ie6Notice.innerHTML = '<p class="title">It seems like you are using Internet Explorer 6 or lower.</p><p>IE6 is an outdated web browser that cannot provide the rich web experience that a modern web browser is able to.  This site may not display and function correctly as a result.</p><p>You may want to upgrade to one of these newer web browsers:</p><ul class="browsers"><li><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx" title="Download Internet Explorer 9">Download Internet Explorer 9</a></li><li><a href="http://www.mozilla.com/en-US/firefox/" title="Download Mozilla Firefox">Download Mozilla Firefox</a></li><li><a href="http://www.google.com/chrome" title="Download Google Chrome">Download Google Chrome</a></li></ul><p class="hide-notice"><a href="#" onclick="document.getElementById(\'ie6-notice\').style.display = \'none\'; return false;" title="Hide this notice" rel="external">Hide this notice</a></p>';
		document.body.appendChild(ie6Notice);
	}
}

// verify the captcha
function verifyCaptcha(captchaFieldid){
	var url = window.CR + '/ajax/verify-captcha?area=' + captchaFieldid + '&captcha=' + $('#' + captchaFieldid)[0].value;
	var valFormIndex = getValFormIndex(captchaFieldid);
	valForms[valFormIndex].ajaxRunning[captchaFieldid] = true;

	$.ajax({
		   url: url
		   , type: 'get'
		   , dataType: 'text'
		   , cache: false
		   , complete: function(ajaxReturn) {
			   				var response = ajaxReturn.responseText;
							var error = response == '0' ? ' is incorrect.' : false;
							
							valForms[valFormIndex].errorHandler($('#' + captchaFieldid)[0], error);
							valForms[valFormIndex].ajaxRunning[captchaFieldid] = false;
						}
			});
	
}

function refreshCaptcha(formid) {
	var textInput = byId(formid + '-captcha');
	textInput.value = '';
	byId(formid + '-captcha-img').src = '/ajax/show-captcha?area=' + formid + '-captcha&amp;k=' + Math.random();
	textInput.focus();
}

function refreshImg(id){
	var img = byId(id);
	if(inString(img.src, '?')){
		img.src = img.src + '&k='+Math.random();
	}
	else{
		img.src = img.src + '?k='+Math.random();
	}
}

function showFlash(src, w, h, container, parameters, variables){
	alert('decremented, use swfobject.embedSWF(window.CR + \'/swf/player.swf\', containerid, w, h, \'9.0.0\', \'expressInstall.swf\', variables, parameters);'); return;
	var s1 = new SWFObject(src, 'mediaplayer', w, h,'7');
	if(parameters){
		parameters = parameters.split('&');
		for(var i = 0; i < parameters.length; i++){
			var parts = parameters[i].split('=');
			s1.addParam(parts[0], parts[1]);
		}
	}
	if(variables){
		s1.addParam('flashvars', variables);
	} 
	if(!s1.write(container)){
		$(container).innerHTML = '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Click here to get the flash player.</a>';
	}
}

//controlbar: over, under
function showPlayer(flv, w, h, containerid, preview, skin, controlbar){
	var parameters = {};
	parameters.allowfullscreen = true;
	parameters.allowscriptaccess = 'always';
	parameters.wmode = 'opaque';
	
	var variables = {file: flv};
	if(preview){
		variables.image = preview;
	}
	if(skin){
		variables.skin = skin;
	}
	if(controlbar){
		variables.controlbar = controlbar;
	}
	swfobject.embedSWF(window.CR + '/swf/player.swf', containerid, w, h, '9.0.0', 'expressInstall.swf', variables, parameters);
}

// skin: (default) | bekle
// controlbar: bottom (default) | top | over | none
// autostart: false (default) | true
// stretching: uniform (default) | fill | exactfit | none
// volume: (integer)
// mute: false (default) | true
function showVideo(flv, w, h, containerid, image, skin, controlbar, autostart, stretching, volume, mute) {
	var parameters = {};
	// Standard parameters
	parameters.allowfullscreen = true;
	parameters.allowscriptaccess = 'always';
	parameters.wmode = 'opaque';
	
	// Flash variables
	var variables = {file: flv};
	if (image !== undefined){
		variables.image = window.CR + '/images/video-previews/' + image;
	}
	if (skin !== undefined){
		variables.skin = window.CR + '/swf/skins/' + skin + '/overlay.swf';
	}
	variables.controlbar = controlbar === undefined ? 'bottom' : controlbar;
	variables.autostart = autostart === undefined ? 'false' : autostart;
	variables.stretching = stretching === undefined ? 'uniform' : stretching;
	variables.volume = volume === undefined ? 100 : volume;
	variables.mute = mute === undefined ? 'false' : mute;
	
	swfobject.embedSWF(window.CR + '/swf/player.swf', containerid, w, h, '9.0.0', 'expressInstall.swf', variables, parameters);
}


function textAreaExp(id){
	var label = $('label[for="' + id + '"]');
	var header = '';
	if(label){
		header = '<h3>' + label[0].innerHTML + '</h3>';
	}

	var html = '<div class="emg-form">' + header + '<textarea rows="25" cols="100" id="' + id + '-expanded" class="fluid">' + $('#' + id)[0].value + '</textarea><br /><button onclick="$(\'#' + id + '\')[0].value = $(\'#' + id + '-expanded\')[0].value; modal.close();">Finish</button></div>';
	modal.load();
	modal.content(html);
}

//use to show all the properties of an object;
function alerto(obj, hideValues){
	var output = '';
	for (var prop in obj ) {
		output += 'object.' + prop;
		if(hideValues != true){
			output += ' = ' + obj[prop] 
		}
		output += "\n";
	}
	alert(output);
}


function checkedToStr(inputName){
	var checkboxes = document.getElementsByName(inputName);
	var values = new Array();
	for(var i=0; i<checkboxes.length; i++){
		if(checkboxes[i].checked){
			values[values.length] = checkboxes[i].value;
		}
	}
	return values.join('-');
}

function moneyFormat(value, nosymbol, cents) {
	if (isNaN(value)) {
		var formatted = '0.00';
	}
	else {
		//var formatted = Math.round(value*100)/100;
		var formatted = Math.round(value*1000)/1000; //use 1000 for partial cents
		formatted = formatted.toString();
		
		if (formatted.indexOf('.') == -1) {
			formatted += '.00';
		}
		else {
			var parts = formatted.split('.');
			if (parts[1].length == 1) {
				formatted += '0';
			}
		}
		// Thousands commas
		if (formatted.length >= 7) {
			var parts = formatted.split('.');
			var integer = parts[0];
			var rgx = /(\d+)(\d{3})/;
			while (rgx.test(integer)) {
				integer = integer.replace(rgx, '$1' + ',' + '$2');
			}
			formatted = integer + '.' + parts[1];
		}
	}
	if(!nosymbol && !cents){
		formatted = '$' + formatted;
	}
	// Cent symbol
	else if (cents && formatted < 1) {
		return formatted * 100 + '\u00a2';
	}
	return formatted;
}

function emailInUse(emailFieldid){
	checkExist('email', emailFieldid, false);
}

function emailNotExist(emailFieldid){
	checkExist('email', emailFieldid, true);
}

function zipExist(zipFieldid){
	checkExist('zip', zipFieldid, true);
}

function checkExist(field, fieldid, valExists){
	if($('#' + fieldid)[0].value == ''){
		return;
	}
	var url = window.CR + '/ajax/check-exist/' + field + '?check-value=' + $('#' + fieldid)[0].value;
	var valFormIndex = getValFormIndex(fieldid);
	valForms[valFormIndex].ajaxRunning[fieldid] = true;
	$.ajax({
		   url: url
		   , type: 'get'
		   , dataType: 'text'
		   , cache: false
		   , complete: function(ajaxReturn) {
						   	if (ajaxReturn.status == '404') { // page not found
								window.location = window.CR + '/error';
								return;
							}
							
			   				var response = ajaxReturn.responseText;
							
							if(valExists){  // for reset password form
								var error = response == '0' ? ' does not exist.' : false;
							}
							else{
								var error = response == '1' ? ' already in use.' : false;
							}
							
							valForms[valFormIndex].errorHandler($('#' + fieldid)[0], error);
							valForms[valFormIndex].ajaxRunning[fieldid] = false;
						}
		   });
}

// Scrolls to hash instead of instant jump
// Also doesn't append hash to current url
// Requires jquery
// Usage: enableHashScroll('a');
// Usage: enableHashScroll(['a', '.nav a]], 1, 16);
function enableHashScroll(anchorSelectors, duration, offset) {
	// Set default duration to 1 second
	duration = isNaN(duration) ? 1000 : duration * 1000;
	offset = isNaN(offset) ? 0 : offset;
	if (!isArray(anchorSelectors)) {
		anchorSelectors = [anchorSelectors];
	}
	
	// For each group of anchor selectors
	$(anchorSelectors).each(function() {
		anchorSelector = $(this).get();
		anchorSelector = anchorSelector === undefined ? 'a' : anchorSelector;
		
		// Anchor events
		$(anchorSelector + '[href^="#"]:not([href="#"]').click(function() {
			this.blur();
			var target = $(this.hash);
			if (target[0]) {
				$('html, body').animate({scrollTop: target.offset().top - offset}, duration);
			}
			return false;
		});
	});
}

// Get hash value from url
function getHash(href) {
	return href.split(/#/)[1];
}

// Get document height, or viewport if body height is less
function getDocHeight() {
	return Math.max(
		Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
		Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
		Math.max(document.body.clientHeight, document.documentElement.clientHeight)
	);
}

// IE select expand
// Usage: ieSelectExpand('select.ie-expand')
function ieSelectExpand(selectSelector) {
	if (selectSelector === undefined) {
		selectSelector = 'select.ie-expand';
	}
	if ($.browser.msie) {
		$(selectSelector).bind('mouseover focus', function() {
			$(this).addClass('expanded').removeClass('clicked');
		}).bind('click', function() {
			$(this).toggleClass('clicked');
		}).bind('mouseout', function() {
			if (!$(this).hasClass('clicked')) {
				$(this).removeClass('expanded');
			}
		}).bind('blur', function() {
			$(this).removeClass('expanded clicked');
		});
	}
}

// Set/append return false
function setOnclickFalse(el, replaceOnclick) {
	if (replaceOnclick == true) {
		el.setAttribute('onclick', 'return false;');
	}
	else {
		var originalOnclick = el.onclick;
		el.onclick = (function(e) {
			if (originalOnclick) {
				originalOnclick();
			}
			return false;
		});
	}
}

// Trim
if (typeof(String.prototype.trim) === "undefined") {
	String.prototype.trim = function() {
		return String(this).replace(/^\s+|\s+$/g, '');
	};
}

//use to concat token to action requests
//function is useful when using ajax to login
//currently being used in checkout.js
function tokenInit(){
	var url = window.CR + '/ajax/account/token';
	var callBackComplete = function(ajaxReturn) {				
		if(!inString(ajaxReturn.responseText, 'lv2-token=')){ //token not available, something could be wrong
			window.TOKEN = '';
			return;
		}
		
		window.TOKEN = ajaxReturn.responseText;
		
		//handle forms
		var forms = $('form');
		for(var i = 0; i < forms.length; i++){
			if(inString(forms[i].action, 'lv2-token=')){ //already has token, potential bugs with user logging in n out with differnt accounts
				continue;	
			}
			if(inString(forms[i].action, window.CR + '/action')){ //if request is an action page
				if(inString(forms[i].action, '?')){
					forms[i].action += '&' + ajaxReturn.responseText;
				}
				else{
					forms[i].action += '?' + ajaxReturn.responseText;
				}
			}
		}
		
		//handle anchors
		var anchors = $('a');
		for(var i = 0; i < anchors.length; i++){
			if(inString(anchors[i].href, 'lv2-token=')){ //already has token, potential bugs with user logging in n out with differnt accounts
				continue;	
			}
			if(inString(anchors[i].href, window.CR + '/action')){ //if request is an action page
				if(inString(anchors[i].href, '?')){
					anchors[i].href += '&' + ajaxReturn.responseText;
				}
				else{
					anchors[i].href += '?' + ajaxReturn.responseText;
				}
			}
		}
	};
	//use ajax to grab token
	$.ajax({url: url, complete: callBackComplete});
	
}

function isArray(o) {
	return Object.prototype.toString.call(o) === '[object Array]';
}

function inString(haystack, needle){
	if(isArray(haystack)){
		alert('use inArray() for ' + needle);
		return false;
	}
	var index = haystack.indexOf(needle);
	
	if (index != -1) {
		return true;	
	}
	
	return false;	
}

function inArray(needle, haystack){
	var index = $.inArray(needle, haystack);
	
	if (index != -1) {
		return true;	
	}
	
	return false;
}

function byId(id){
	return document.getElementById(id);
}

// The .bind method from Prototype.js 
if (!Function.prototype.bind) { // check if native implementation available
  Function.prototype.bind = function(){ 
    var fn = this, args = Array.prototype.slice.call(arguments),
        object = args.shift(); 
    return function(){ 
      return fn.apply(object, 
        args.concat(Array.prototype.slice.call(arguments))); 
    }; 
  };
}

// Scrollbar Width
function getScrollBarWidth() {  
	var inner = document.createElement('p');
	inner.style.width = "100%";
	inner.style.height = "200px";
	
	var outer = document.createElement('div');
	outer.style.position = "absolute";
	outer.style.top = "0px";
	outer.style.left = "0px";
	outer.style.visibility = "hidden";
	outer.style.width = "200px";
	outer.style.height = "150px";
	outer.style.overflow = "hidden";
	outer.appendChild (inner);
	
	document.body.appendChild (outer);
	var w1 = inner.offsetWidth;
	outer.style.overflow = 'scroll';
	var w2 = inner.offsetWidth;
	if (w1 == w2) w2 = outer.clientWidth;
	
	document.body.removeChild (outer);
	
	return (w1 - w2);
};

function youtubeEmbed(selector, url, w, h, autoplay){
	//get video id
	var parts = url.split('?');
	var variables = parts[1].split('&');
	for(var i = 0; i < variables.length; i++){
		var variableParts = variables[i].split('=');
		if(variableParts[0] == 'v'){
			var id = variableParts[1];
		}
	}
	
	if(id == null){
		return;	
	}
	
	if(autoplay == null || !autoplay){
		autoplay = '0';
	}
	else if(autoplay){
		autoplay = '1';	
	}
	
	var html = '<object width="' + w + '" height="' + h + '">';
	html += '<param name="movie" value="http://www.youtube.com/v/' + id + '?fs=1&amp;hl=en_US&autoplay=' + autoplay + '"></param>';
	html += '<param name="allowFullScreen" value="true"></param>';
	html += '<param name="allowscriptaccess" value="always"></param>';
	html += '<param name="wmode" value="opaque"></param>';
	html += '<embed src="http://www.youtube.com/v/' + id + '?fs=1&amp;hl=en_US&autoplay=' + autoplay + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="opaque" width="' + w + '" height="' + h + '"></embed>';
	html += '</object>';

	$(selector)[0].innerHTML = html;
}

/* browser-detect.js.php */
/*<script>*/
// Browser name:	BrowserDetect.browser
// Browser version:	BrowserDetect.version
// OS name:			BrowserDetect.OS
/* July 16 09 */ 
/*
Copyright Â© 2008 Eckx Media Group, LLC. All rights reserved.
Eckx Media Group respects the intellectual property of others, and we ask our users to do the same.
*/

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.userAgent,
			subString: "iPhone",
			identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

/* functions.js.php */
/*<script>*/
function siteInit() {
	homepageSlideshow();
	
	// Heading stars (span)
	$('h2').each(function() {
		var text = $(this).text();
		$(this).html('<span>' + text + '</span>');
	});
	
	signUpForm();
	
	// Events Calendar
	var calendar = new Slideshow({previousNextNavClass: '#calendar-container ol.nav'
								, navClass: '#calendar-container ol.month-nav'
								, slidesClass: '#calendar-container ol.months'
								, autoplay: false
								, slideDuration: 5
								, transition: 'scroll'
								, transitionDuration: 0.5
								});

	// ipad hover
	//if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
		$("ul#nav li.parent > span").click(function(){
			$(this).closest('li.parent').toggleClass('hover');
		});
	//}
}

function homepageSlideshow() {
	this.slides = $('#slideshow ul.slides li');
	this.numSlides = this.slides.length;
	this.slideWidth = $(this.slides[0]).width();
	this.leftPadding = 30;
	this.slideDuration = 3;
	this.transitionDuration = 0.5;
	this.current = 2;
	this.autoplay = true;
	this.windowFocus = true;
	
	this.navs = $('#slideshow ul.slides a.slide-link');
	this.curNav = this.navs[this.current];
	
	this.plays = 0;
	
	// Event handler
	$(this.navs).each((function(i, el) {
		$(el).click((function() {
			this.autoplay = false;
			
			this.curNav = el;
			this.slide();
			
			return false;
		}).bind(this));
	}).bind(this));
	
	$(window).blur((function() {
		this.windowFocus = false;
	}).bind(this));
	$(window).focus((function() {
		if (!this.windowFocus) {
			this.windowFocus = true;
			this.play();
		}
	}).bind(this));
	
	this.slide = function() {
		var slideIndex = slides.index($(this.curNav).closest('li'));
		this.current = slideIndex;
		
		// n + 2 to get items after
		$('#slideshow ul.slides li:nth-child(n+' + (slideIndex + 2) + ')').each((function(i, el) {
			var displacement = this.slideWidth + (this.slides.index(el) * this.leftPadding)
			$(el).animate({marginLeft: displacement}, this.transitionDuration * 1000, 'swing');
		}).bind(this));
		// -n + 1 to get item & items before
		$('#slideshow ul.slides li:nth-child(-n+' + (slideIndex + 1) + ')').each((function(i, el) {
			var displacement = (this.slides.index(el) * this.leftPadding)
			$(el).animate({marginLeft: displacement}, this.transitionDuration * 1000, 'swing');
		}).bind(this));
	}
	
	this.play = function() {
		if (this.plays < 1) {
			this.plays++;
			setTimeout((function() {
				if (this.autoplay && this.windowFocus) {				
					this.current = (this.current == 0) ? this.numSlides - 1 : this.current - 1;
					this.curNav = this.navs[this.current];
					
					this.slide();
					
					this.plays--;
					
					this.play();
				}
				else {
					this.plays--;
				}
			}).bind(this), (this.slideDuration + this.transitionDuration) * 1000);
		}
	}
	
	this.play();
}

// Clear email and open in new
function signUpForm() {
	$('.sign-up-form').attr('target', '_blank')
	.submit(function() {
		var emailField = $('input[name="MERGE0"]', this)[0];
		if (emailField.value == emailField.defaultValue) {
			emailField.value = '';
		}
	});
}

// YouTube Channel Embed
/*
Copyright 2011 : Simone Gianni <simoneg@apache.org>

Released under The Apache License 2.0 
http://www.apache.org/licenses/LICENSE-2.0

*/
(function() {
    function createPlayer(jqe, video, options) {
        var ifr = $('iframe', jqe);
        if (ifr.length === 0) {
            ifr = $('<iframe scrolling="no">');
            ifr.addClass('player');
        }
        var src = 'http://www.youtube.com/embed/' + video.id;
        if (options.playopts) {
            src += '?';
            for (var k in options.playopts) {
                src+= k + '=' + options.playopts[k] + '&';
            }  
            src += '_a=b';
        }
        ifr.attr('src', src);
        jqe.prepend(ifr);  
    }
    
    function createCarousel(jqe, videos, options) {
        var car = $('div.carousel', jqe);
        if (car.length === 0) {
            car = $('<div>');
            car.addClass('carousel');
            jqe.append(car);
            
        }
        $.each(videos, function(i,video) {
            options.thumbnail(car, video, options); 
        });
    }
    
    function createThumbnail(jqe, video, options) {
        var imgurl = video.thumbnails[0].url;
		var thumb = $('<a class="thumbnail"></a>');
		var caption = $('<span class="caption">' + video.title + '</span>');
        var img = $('img[src="' + imgurl + '"]');
        if (img.length !== 0) return;
        img = $('<img />');    
        //img.addClass('thumbnail');
        //jqe.append(img);
        img.attr('src', imgurl);
        thumb.attr('href', '#');
        thumb.attr('title', video.title);
		thumb.append(img);
		thumb.append(caption);
		jqe.append(thumb);
        thumb.click(function() {
            options.player(options.maindiv, video, $.extend(true,{},options,{playopts:{autoplay:1}}));
			return false;
        });
    }
    
    var defoptions = {
        autoplay: false,
        user: null,
        carousel: createCarousel,
        player: createPlayer,
        thumbnail: createThumbnail,
        loaded: function() {},
        playopts: {
            autoplay: 0,
            egm: 1,
            autohide: 0,
            fs: 1,
            showinfo: 1
        }
    };
    
    
    $.fn.extend({
        youTubeChannel: function(options) {
            var md = $(this);
            md.addClass('youtube');
            md.addClass('youtube-channel');
            var allopts = $.extend(true, {}, defoptions, options);
            allopts.maindiv = md;
            $.getJSON('http://gdata.youtube.com/feeds/users/' + allopts.user + '/uploads?alt=json-in-script&format=5&callback=?', null, function(data) {
                var feed = data.feed;
                var videos = [];
                $.each(feed.entry, function(i, entry) {
                    var video = {
                        title: entry.title.$t,
                        id: entry.id.$t.match('[^/]*$'),
                        thumbnails: entry.media$group.media$thumbnail
                    };
                    videos.push(video);
                });
                allopts.allvideos = videos;
                allopts.carousel(md, videos, allopts);
                allopts.player(md, videos[0], allopts);
                allopts.loaded(videos, allopts);
            });
        } 
    });
    
})();
        
$(function() {
    $('#youtube-channel').youTubeChannel({user:'sanfranciscogop'});
});

/* jquery.easing-1.3.pack.js.php */
/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('h.i[\'1a\']=h.i[\'z\'];h.O(h.i,{y:\'D\',z:9(x,t,b,c,d){6 h.i[h.i.y](x,t,b,c,d)},17:9(x,t,b,c,d){6 c*(t/=d)*t+b},D:9(x,t,b,c,d){6-c*(t/=d)*(t-2)+b},13:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t+b;6-c/2*((--t)*(t-2)-1)+b},X:9(x,t,b,c,d){6 c*(t/=d)*t*t+b},U:9(x,t,b,c,d){6 c*((t=t/d-1)*t*t+1)+b},R:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t+b;6 c/2*((t-=2)*t*t+2)+b},N:9(x,t,b,c,d){6 c*(t/=d)*t*t*t+b},M:9(x,t,b,c,d){6-c*((t=t/d-1)*t*t*t-1)+b},L:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t*t+b;6-c/2*((t-=2)*t*t*t-2)+b},K:9(x,t,b,c,d){6 c*(t/=d)*t*t*t*t+b},J:9(x,t,b,c,d){6 c*((t=t/d-1)*t*t*t*t+1)+b},I:9(x,t,b,c,d){e((t/=d/2)<1)6 c/2*t*t*t*t*t+b;6 c/2*((t-=2)*t*t*t*t+2)+b},G:9(x,t,b,c,d){6-c*8.C(t/d*(8.g/2))+c+b},15:9(x,t,b,c,d){6 c*8.n(t/d*(8.g/2))+b},12:9(x,t,b,c,d){6-c/2*(8.C(8.g*t/d)-1)+b},Z:9(x,t,b,c,d){6(t==0)?b:c*8.j(2,10*(t/d-1))+b},Y:9(x,t,b,c,d){6(t==d)?b+c:c*(-8.j(2,-10*t/d)+1)+b},W:9(x,t,b,c,d){e(t==0)6 b;e(t==d)6 b+c;e((t/=d/2)<1)6 c/2*8.j(2,10*(t-1))+b;6 c/2*(-8.j(2,-10*--t)+2)+b},V:9(x,t,b,c,d){6-c*(8.o(1-(t/=d)*t)-1)+b},S:9(x,t,b,c,d){6 c*8.o(1-(t=t/d-1)*t)+b},Q:9(x,t,b,c,d){e((t/=d/2)<1)6-c/2*(8.o(1-t*t)-1)+b;6 c/2*(8.o(1-(t-=2)*t)+1)+b},P:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d)==1)6 b+c;e(!p)p=d*.3;e(a<8.w(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.r(c/a);6-(a*8.j(2,10*(t-=1))*8.n((t*d-s)*(2*8.g)/p))+b},H:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d)==1)6 b+c;e(!p)p=d*.3;e(a<8.w(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.r(c/a);6 a*8.j(2,-10*t)*8.n((t*d-s)*(2*8.g)/p)+c+b},T:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d/2)==2)6 b+c;e(!p)p=d*(.3*1.5);e(a<8.w(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.r(c/a);e(t<1)6-.5*(a*8.j(2,10*(t-=1))*8.n((t*d-s)*(2*8.g)/p))+b;6 a*8.j(2,-10*(t-=1))*8.n((t*d-s)*(2*8.g)/p)*.5+c+b},F:9(x,t,b,c,d,s){e(s==u)s=1.l;6 c*(t/=d)*t*((s+1)*t-s)+b},E:9(x,t,b,c,d,s){e(s==u)s=1.l;6 c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},16:9(x,t,b,c,d,s){e(s==u)s=1.l;e((t/=d/2)<1)6 c/2*(t*t*(((s*=(1.B))+1)*t-s))+b;6 c/2*((t-=2)*t*(((s*=(1.B))+1)*t+s)+2)+b},A:9(x,t,b,c,d){6 c-h.i.v(x,d-t,0,c,d)+b},v:9(x,t,b,c,d){e((t/=d)<(1/2.k)){6 c*(7.q*t*t)+b}m e(t<(2/2.k)){6 c*(7.q*(t-=(1.5/2.k))*t+.k)+b}m e(t<(2.5/2.k)){6 c*(7.q*(t-=(2.14/2.k))*t+.11)+b}m{6 c*(7.q*(t-=(2.18/2.k))*t+.19)+b}},1b:9(x,t,b,c,d){e(t<d/2)6 h.i.A(x,t*2,0,c,d)*.5+b;6 h.i.v(x,t*2-d,0,c,d)*.5+c*.5+b}});',62,74,'||||||return||Math|function|||||if|var|PI|jQuery|easing|pow|75|70158|else|sin|sqrt||5625|asin|||undefined|easeOutBounce|abs||def|swing|easeInBounce|525|cos|easeOutQuad|easeOutBack|easeInBack|easeInSine|easeOutElastic|easeInOutQuint|easeOutQuint|easeInQuint|easeInOutQuart|easeOutQuart|easeInQuart|extend|easeInElastic|easeInOutCirc|easeInOutCubic|easeOutCirc|easeInOutElastic|easeOutCubic|easeInCirc|easeInOutExpo|easeInCubic|easeOutExpo|easeInExpo||9375|easeInOutSine|easeInOutQuad|25|easeOutSine|easeInOutBack|easeInQuad|625|984375|jswing|easeInOutBounce'.split('|'),0,{}))

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */


/* jquery.fancybox-1.3.4.pack.js.php */
/*
 * FancyBox - jQuery Plugin
 * Simple and fancy lightbox alternative
 *
 * Examples and documentation at: http://fancybox.net
 * 
 * Copyright (c) 2008 - 2010 Janis Skarnelis
 * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
 * 
 * Version: 1.3.4 (11/11/2010)
 * Requires: jQuery v1.3+
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

;(function(b){var m,t,u,f,D,j,E,n,z,A,q=0,e={},o=[],p=0,d={},l=[],G=null,v=new Image,J=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,W=/[^\.]\.(swf)\s*$/i,K,L=1,y=0,s="",r,i,h=false,B=b.extend(b("<div/>")[0],{prop:0}),M=b.browser.msie&&b.browser.version<7&&!window.XMLHttpRequest,N=function(){t.hide();v.onerror=v.onload=null;G&&G.abort();m.empty()},O=function(){if(false===e.onError(o,q,e)){t.hide();h=false}else{e.titleShow=false;e.width="auto";e.height="auto";m.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>');
F()}},I=function(){var a=o[q],c,g,k,C,P,w;N();e=b.extend({},b.fn.fancybox.defaults,typeof b(a).data("fancybox")=="undefined"?e:b(a).data("fancybox"));w=e.onStart(o,q,e);if(w===false)h=false;else{if(typeof w=="object")e=b.extend(e,w);k=e.title||(a.nodeName?b(a).attr("title"):a.title)||"";if(a.nodeName&&!e.orig)e.orig=b(a).children("img:first").length?b(a).children("img:first"):b(a);if(k===""&&e.orig&&e.titleFromAlt)k=e.orig.attr("alt");c=e.href||(a.nodeName?b(a).attr("href"):a.href)||null;if(/^(?:javascript)/i.test(c)||
c=="#")c=null;if(e.type){g=e.type;if(!c)c=e.content}else if(e.content)g="html";else if(c)g=c.match(J)?"image":c.match(W)?"swf":b(a).hasClass("iframe")?"iframe":c.indexOf("#")===0?"inline":"ajax";if(g){if(g=="inline"){a=c.substr(c.indexOf("#"));g=b(a).length>0?"inline":"ajax"}e.type=g;e.href=c;e.title=k;if(e.autoDimensions)if(e.type=="html"||e.type=="inline"||e.type=="ajax"){e.width="auto";e.height="auto"}else e.autoDimensions=false;if(e.modal){e.overlayShow=true;e.hideOnOverlayClick=false;e.hideOnContentClick=
false;e.enableEscapeButton=false;e.showCloseButton=false}e.padding=parseInt(e.padding,10);e.margin=parseInt(e.margin,10);m.css("padding",e.padding+e.margin);b(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){b(this).replaceWith(j.children())});switch(g){case "html":m.html(e.content);F();break;case "inline":if(b(a).parent().is("#fancybox-content")===true){h=false;break}b('<div class="fancybox-inline-tmp" />').hide().insertBefore(b(a)).bind("fancybox-cleanup",function(){b(this).replaceWith(j.children())}).bind("fancybox-cancel",
function(){b(this).replaceWith(m.children())});b(a).appendTo(m);F();break;case "image":h=false;b.fancybox.showActivity();v=new Image;v.onerror=function(){O()};v.onload=function(){h=true;v.onerror=v.onload=null;e.width=v.width;e.height=v.height;b("<img />").attr({id:"fancybox-img",src:v.src,alt:e.title}).appendTo(m);Q()};v.src=c;break;case "swf":e.scrolling="no";C='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+e.width+'" height="'+e.height+'"><param name="movie" value="'+c+
'"></param>';P="";b.each(e.swf,function(x,H){C+='<param name="'+x+'" value="'+H+'"></param>';P+=" "+x+'="'+H+'"'});C+='<embed src="'+c+'" type="application/x-shockwave-flash" width="'+e.width+'" height="'+e.height+'"'+P+"></embed></object>";m.html(C);F();break;case "ajax":h=false;b.fancybox.showActivity();e.ajax.win=e.ajax.success;G=b.ajax(b.extend({},e.ajax,{url:c,data:e.ajax.data||{},error:function(x){x.status>0&&O()},success:function(x,H,R){if((typeof R=="object"?R:G).status==200){if(typeof e.ajax.win==
"function"){w=e.ajax.win(c,x,H,R);if(w===false){t.hide();return}else if(typeof w=="string"||typeof w=="object")x=w}m.html(x);F()}}}));break;case "iframe":Q()}}else O()}},F=function(){var a=e.width,c=e.height;a=a.toString().indexOf("%")>-1?parseInt((b(window).width()-e.margin*2)*parseFloat(a)/100,10)+"px":a=="auto"?"auto":a+"px";c=c.toString().indexOf("%")>-1?parseInt((b(window).height()-e.margin*2)*parseFloat(c)/100,10)+"px":c=="auto"?"auto":c+"px";m.wrapInner('<div style="width:'+a+";height:"+c+
";overflow: "+(e.scrolling=="auto"?"auto":e.scrolling=="yes"?"scroll":"hidden")+';position:relative;"></div>');e.width=m.width();e.height=m.height();Q()},Q=function(){var a,c;t.hide();if(f.is(":visible")&&false===d.onCleanup(l,p,d)){b.event.trigger("fancybox-cancel");h=false}else{h=true;b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");f.is(":visible")&&d.titlePosition!=="outside"&&f.css("height",f.height());l=o;p=q;d=e;if(d.overlayShow){u.css({"background-color":d.overlayColor,
opacity:d.overlayOpacity,cursor:d.hideOnOverlayClick?"pointer":"auto",height:b(document).height()});if(!u.is(":visible")){M&&b("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});u.show()}}else u.hide();i=X();s=d.title||"";y=0;n.empty().removeAttr("style").removeClass();if(d.titleShow!==false){if(b.isFunction(d.titleFormat))a=d.titleFormat(s,l,p,d);else a=s&&s.length?
d.titlePosition=="float"?'<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">'+s+'</td><td id="fancybox-title-float-right"></td></tr></table>':'<div id="fancybox-title-'+d.titlePosition+'">'+s+"</div>":false;s=a;if(!(!s||s==="")){n.addClass("fancybox-title-"+d.titlePosition).html(s).appendTo("body").show();switch(d.titlePosition){case "inside":n.css({width:i.width-d.padding*2,marginLeft:d.padding,marginRight:d.padding});
y=n.outerHeight(true);n.appendTo(D);i.height+=y;break;case "over":n.css({marginLeft:d.padding,width:i.width-d.padding*2,bottom:d.padding}).appendTo(D);break;case "float":n.css("left",parseInt((n.width()-i.width-40)/2,10)*-1).appendTo(f);break;default:n.css({width:i.width-d.padding*2,paddingLeft:d.padding,paddingRight:d.padding}).appendTo(f)}}}n.hide();if(f.is(":visible")){b(E.add(z).add(A)).hide();a=f.position();r={top:a.top,left:a.left,width:f.width(),height:f.height()};c=r.width==i.width&&r.height==
i.height;j.fadeTo(d.changeFade,0.3,function(){var g=function(){j.html(m.contents()).fadeTo(d.changeFade,1,S)};b.event.trigger("fancybox-change");j.empty().removeAttr("filter").css({"border-width":d.padding,width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2});if(c)g();else{B.prop=0;b(B).animate({prop:1},{duration:d.changeSpeed,easing:d.easingChange,step:T,complete:g})}})}else{f.removeAttr("style");j.css("border-width",d.padding);if(d.transitionIn=="elastic"){r=V();j.html(m.contents());
f.show();if(d.opacity)i.opacity=0;B.prop=0;b(B).animate({prop:1},{duration:d.speedIn,easing:d.easingIn,step:T,complete:S})}else{d.titlePosition=="inside"&&y>0&&n.show();j.css({width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2}).html(m.contents());f.css(i).fadeIn(d.transitionIn=="none"?0:d.speedIn,S)}}}},Y=function(){if(d.enableEscapeButton||d.enableKeyboardNav)b(document).bind("keydown.fb",function(a){if(a.keyCode==27&&d.enableEscapeButton){a.preventDefault();b.fancybox.close()}else if((a.keyCode==
37||a.keyCode==39)&&d.enableKeyboardNav&&a.target.tagName!=="INPUT"&&a.target.tagName!=="TEXTAREA"&&a.target.tagName!=="SELECT"){a.preventDefault();b.fancybox[a.keyCode==37?"prev":"next"]()}});if(d.showNavArrows){if(d.cyclic&&l.length>1||p!==0)z.show();if(d.cyclic&&l.length>1||p!=l.length-1)A.show()}else{z.hide();A.hide()}},S=function(){if(!b.support.opacity){j.get(0).style.removeAttribute("filter");f.get(0).style.removeAttribute("filter")}e.autoDimensions&&j.css("height","auto");f.css("height","auto");
s&&s.length&&n.show();d.showCloseButton&&E.show();Y();d.hideOnContentClick&&j.bind("click",b.fancybox.close);d.hideOnOverlayClick&&u.bind("click",b.fancybox.close);b(window).bind("resize.fb",b.fancybox.resize);d.centerOnScroll&&b(window).bind("scroll.fb",b.fancybox.center);if(d.type=="iframe")b('<iframe id="fancybox-frame" name="fancybox-frame'+(new Date).getTime()+'" frameborder="0" hspace="0" '+(b.browser.msie?'allowtransparency="true""':"")+' scrolling="'+e.scrolling+'" src="'+d.href+'"></iframe>').appendTo(j);
f.show();h=false;b.fancybox.center();d.onComplete(l,p,d);var a,c;if(l.length-1>p){a=l[p+1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}if(p>0){a=l[p-1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}},T=function(a){var c={width:parseInt(r.width+(i.width-r.width)*a,10),height:parseInt(r.height+(i.height-r.height)*a,10),top:parseInt(r.top+(i.top-r.top)*a,10),left:parseInt(r.left+(i.left-r.left)*a,10)};if(typeof i.opacity!=="undefined")c.opacity=a<0.5?0.5:a;f.css(c);
j.css({width:c.width-d.padding*2,height:c.height-y*a-d.padding*2})},U=function(){return[b(window).width()-d.margin*2,b(window).height()-d.margin*2,b(document).scrollLeft()+d.margin,b(document).scrollTop()+d.margin]},X=function(){var a=U(),c={},g=d.autoScale,k=d.padding*2;c.width=d.width.toString().indexOf("%")>-1?parseInt(a[0]*parseFloat(d.width)/100,10):d.width+k;c.height=d.height.toString().indexOf("%")>-1?parseInt(a[1]*parseFloat(d.height)/100,10):d.height+k;if(g&&(c.width>a[0]||c.height>a[1]))if(e.type==
"image"||e.type=="swf"){g=d.width/d.height;if(c.width>a[0]){c.width=a[0];c.height=parseInt((c.width-k)/g+k,10)}if(c.height>a[1]){c.height=a[1];c.width=parseInt((c.height-k)*g+k,10)}}else{c.width=Math.min(c.width,a[0]);c.height=Math.min(c.height,a[1])}c.top=parseInt(Math.max(a[3]-20,a[3]+(a[1]-c.height-40)*0.5),10);c.left=parseInt(Math.max(a[2]-20,a[2]+(a[0]-c.width-40)*0.5),10);return c},V=function(){var a=e.orig?b(e.orig):false,c={};if(a&&a.length){c=a.offset();c.top+=parseInt(a.css("paddingTop"),
10)||0;c.left+=parseInt(a.css("paddingLeft"),10)||0;c.top+=parseInt(a.css("border-top-width"),10)||0;c.left+=parseInt(a.css("border-left-width"),10)||0;c.width=a.width();c.height=a.height();c={width:c.width+d.padding*2,height:c.height+d.padding*2,top:c.top-d.padding-20,left:c.left-d.padding-20}}else{a=U();c={width:d.padding*2,height:d.padding*2,top:parseInt(a[3]+a[1]*0.5,10),left:parseInt(a[2]+a[0]*0.5,10)}}return c},Z=function(){if(t.is(":visible")){b("div",t).css("top",L*-40+"px");L=(L+1)%12}else clearInterval(K)};
b.fn.fancybox=function(a){if(!b(this).length)return this;b(this).data("fancybox",b.extend({},a,b.metadata?b(this).metadata():{})).unbind("click.fb").bind("click.fb",function(c){c.preventDefault();if(!h){h=true;b(this).blur();o=[];q=0;c=b(this).attr("rel")||"";if(!c||c==""||c==="nofollow")o.push(this);else{o=b("a[rel="+c+"], area[rel="+c+"]");q=o.index(this)}I()}});return this};b.fancybox=function(a,c){var g;if(!h){h=true;g=typeof c!=="undefined"?c:{};o=[];q=parseInt(g.index,10)||0;if(b.isArray(a)){for(var k=
0,C=a.length;k<C;k++)if(typeof a[k]=="object")b(a[k]).data("fancybox",b.extend({},g,a[k]));else a[k]=b({}).data("fancybox",b.extend({content:a[k]},g));o=jQuery.merge(o,a)}else{if(typeof a=="object")b(a).data("fancybox",b.extend({},g,a));else a=b({}).data("fancybox",b.extend({content:a},g));o.push(a)}if(q>o.length||q<0)q=0;I()}};b.fancybox.showActivity=function(){clearInterval(K);t.show();K=setInterval(Z,66)};b.fancybox.hideActivity=function(){t.hide()};b.fancybox.next=function(){return b.fancybox.pos(p+
1)};b.fancybox.prev=function(){return b.fancybox.pos(p-1)};b.fancybox.pos=function(a){if(!h){a=parseInt(a);o=l;if(a>-1&&a<l.length){q=a;I()}else if(d.cyclic&&l.length>1){q=a>=l.length?0:l.length-1;I()}}};b.fancybox.cancel=function(){if(!h){h=true;b.event.trigger("fancybox-cancel");N();e.onCancel(o,q,e);h=false}};b.fancybox.close=function(){function a(){u.fadeOut("fast");n.empty().hide();f.hide();b.event.trigger("fancybox-cleanup");j.empty();d.onClosed(l,p,d);l=e=[];p=q=0;d=e={};h=false}if(!(h||f.is(":hidden"))){h=
true;if(d&&false===d.onCleanup(l,p,d))h=false;else{N();b(E.add(z).add(A)).hide();b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");j.find("iframe").attr("src",M&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank");d.titlePosition!=="inside"&&n.empty();f.stop();if(d.transitionOut=="elastic"){r=V();var c=f.position();i={top:c.top,left:c.left,width:f.width(),height:f.height()};if(d.opacity)i.opacity=1;n.empty().hide();B.prop=1;
b(B).animate({prop:0},{duration:d.speedOut,easing:d.easingOut,step:T,complete:a})}else f.fadeOut(d.transitionOut=="none"?0:d.speedOut,a)}}};b.fancybox.resize=function(){u.is(":visible")&&u.css("height",b(document).height());b.fancybox.center(true)};b.fancybox.center=function(a){var c,g;if(!h){g=a===true?1:0;c=U();!g&&(f.width()>c[0]||f.height()>c[1])||f.stop().animate({top:parseInt(Math.max(c[3]-20,c[3]+(c[1]-j.height()-40)*0.5-d.padding)),left:parseInt(Math.max(c[2]-20,c[2]+(c[0]-j.width()-40)*0.5-
d.padding))},typeof a=="number"?a:200)}};b.fancybox.init=function(){if(!b("#fancybox-wrap").length){b("body").append(m=b('<div id="fancybox-tmp"></div>'),t=b('<div id="fancybox-loading"><div></div></div>'),u=b('<div id="fancybox-overlay"></div>'),f=b('<div id="fancybox-wrap"></div>'));D=b('<div id="fancybox-outer"></div>').append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>').appendTo(f);
D.append(j=b('<div id="fancybox-content"></div>'),E=b('<a id="fancybox-close"></a>'),n=b('<div id="fancybox-title"></div>'),z=b('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),A=b('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));E.click(b.fancybox.close);t.click(b.fancybox.cancel);z.click(function(a){a.preventDefault();b.fancybox.prev()});A.click(function(a){a.preventDefault();b.fancybox.next()});
b.fn.mousewheel&&f.bind("mousewheel.fb",function(a,c){if(h)a.preventDefault();else if(b(a.target).get(0).clientHeight==0||b(a.target).get(0).scrollHeight===b(a.target).get(0).clientHeight){a.preventDefault();b.fancybox[c>0?"prev":"next"]()}});b.support.opacity||f.addClass("fancybox-ie");if(M){t.addClass("fancybox-ie6");f.addClass("fancybox-ie6");b('<iframe id="fancybox-hide-sel-frame" src="'+(/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank")+'" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(D)}}};
b.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false,scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:"#777",titleShow:true,titlePosition:"float",titleFormat:null,titleFromAlt:false,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",
easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true,enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};b(document).ready(function(){b.fancybox.init()})})(jQuery);

/* jquery.fancybox.emg.js.php */
/*<script>*/
/* http://fancybox.net/api
 */
$(document).ready(function() {	
	// Fancybox	
	$('a[href$=".jpg"], a[href$=".png"]').fancybox({
		// fade | elastic | none
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		
		'speedIn'		:	500, 
		'speedOut'		:	250,
		
		'overlayColor'	:	'#000',
		'overlayOpacity':	'0',
		
		// inside | outside | over
		'titlePosition'	:	'inside',
		'titleFormat'	: 	formatTitle,
		
		'cyclic'		:	true,
		'padding'		:	30,
		'margin'		:	50
	});
});

function formatTitle(title, currentArray, currentIndex, currentOpts) {
	return '<div class="nav"><a href="javascript:$.fancybox.prev()" class="nav-previous">Previous</a> ' + (currentIndex + 1) + ' of ' + currentArray.length + ' <a href="javascript:$.fancybox.next()" class="nav-next">Next</a></div>' + (title && title.length ? title : '' );
}

/* jquery.mousewheel-3.0.4.pack.js.php */
/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
* Licensed under the MIT License (LICENSE.txt).
*
* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
* Thanks to: Seamus Leahy for adding deltaX and deltaY
*
* Version: 3.0.4
*
* Requires: 1.2.2+
*/

(function(d){function g(a){var b=a||window.event,i=[].slice.call(arguments,1),c=0,h=0,e=0;a=d.event.fix(b);a.type="mousewheel";if(a.wheelDelta)c=a.wheelDelta/120;if(a.detail)c=-a.detail/3;e=c;if(b.axis!==undefined&&b.axis===b.HORIZONTAL_AXIS){e=0;h=-1*c}if(b.wheelDeltaY!==undefined)e=b.wheelDeltaY/120;if(b.wheelDeltaX!==undefined)h=-1*b.wheelDeltaX/120;i.unshift(a,c,h,e);return d.event.handle.apply(this,i)}var f=["DOMMouseScroll","mousewheel"];d.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=
f.length;a;)this.addEventListener(f[--a],g,false);else this.onmousewheel=g},teardown:function(){if(this.removeEventListener)for(var a=f.length;a;)this.removeEventListener(f[--a],g,false);else this.onmousewheel=null}};d.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);

/* slideshow-v4.js.php */
/*<script>*/
// Requires jquery
// Usage:
/* var slideshow = new Slideshow({previousNextNavClass: '#slideshow ul.previous-next-nav'
								, navClass: '#slideshow ul.nav'
								, slidesClass: '#slideshow ul.slides'
								, autoplay: true
								, slideDuration: 5
								, transition: 'scroll'
								, transitionDuration: 0.5
								//, replaceOnlick = false
								});
*/
function Slideshow(args) {
	// Constructor
	this.construct = function(args) {
		// Required Parameters
		this.previousNextNavClass = args.previousNextNavClass;
		this.navClass = args.navClass;
		this.slidesClass = args.slidesClass;
		// Optional parameters (set default values in 'else' condition)
		this.autoplay = args.autoplay == true ? true : false;
		this.slideDuration = args.slideDuration > 0 ? args.slideDuration : 4;
		this.transition = args.transition;
		this.transitionDuration = args.transitionDuration > 0 ? args.transitionDuration : 1;
		
		// Navs & Slides
		this.previousNextNavs = $(this.previousNextNavClass + ' > li');
		this.navs = $(this.navClass + ' > li');
		this.slides = $(this.slidesClass + ' > li');
		this.count = this.slides.length;
		// Need slides container for 'scroll'
		this.slidesContainer = $(this.slidesClass)[0];
		
		this.scrollAmount = $(this.slidesClass + ' > li:first-child').width();
		
		this.current = args.current > 0 ? args.current : 1;
		this.currentClass = 'current';
		this.currentPreviousClass = 'current-previous';
		this.previousClass = 'previous';
		this.nextClass = 'next';
		
		// Tabbed class for classname handling
		this.tabbed = false;
		
		// Return if elements don't exist
		if (this.slides.length < 1 || (this.navs.length + this.previousNextNavs.length < 1)) {
			return;
		}
		// Create Tabbed instance
		else {
			this.tabbed = new Tabbed({navClass: this.navClass});
		}
		
		// Set slides container width for scroll transition
		if (this.transition == 'scroll') {
			$(this.slidesContainer).width($(this.slides[0]).width() * $(this.slides).length);
		}
		
		this.setEvents();
		
		setTimeout((function() {
			this.play();
		}).bind(this), this.slideDuration * 1000);
	}
	
	// Event handlers
	this.setEvents = function() {
		// Stop autoplay if list item is clicked on
		this.slides.click((function() {
			this.stop();
		}).bind(this));
		
		// Swap events
		$(this.navClass + ' > li > a').each((function(i, el) {
			// Click event
			$(el).click((function() {
				this.swap(el.hash);
				return false;
			}).bind(this, el))
		}).bind(this));
		
		// Previous / Next links
		$(this.previousNextNavClass + ' > li > a').each((function(i, el) {
			$(el).click((function() {
				if ($(el).parent().hasClass(this.previousClass)) {
					this.previous(false);
				}
				else if ($(el).parent().hasClass(this.nextClass)) {
					this.next(false);
				}
				return false;
			}).bind(this, el))
		}).bind(this));
	}
	
	// Autoplay
	this.play = function() {
		if (!this.autoplay) {
			return;
		}
		
		// Go to next slide
		this.next(true);
		
		// Continue autoplay
		setTimeout((function() {
			this.play();
		}).bind(this), (this.slideDuration + this.transitionDuration) * 1000);
	}
	
	// Swap target slide with current
	this.swap = function(target, autoplay) {
		if (!autoplay) {
			this.stop();
		}
		
		// Target slide <li> element
		var targetSlide = $(target);
		var currentSlide = $(this.slides[this.current - 1]);
		
		// Do nothing if swap target is current
		var newCurrent = $(this.slides).index(targetSlide) + 1;
		if (this.current == newCurrent) {
			return;
		}
		
		// Fade
		if (this.transition == 'fade') {
			// Fade out
			// Add currentPreviousClass so we can fade out from the current slide			
			$(currentSlide).addClass(this.currentPreviousClass);
			
			// Fade in			
			$(targetSlide).hide();
			$(targetSlide).fadeIn(this.transitionDuration * 1000, (function() {
				$(this.slides).removeClass(this.currentPreviousClass);
			}).bind(this));
		}
		// Scroll
		else if (this.transition == 'scroll') {
			var displacement = -(this.scrollAmount) * (newCurrent - 1);
			$(this.slidesContainer).animate({marginLeft: displacement}, this.transitionDuration * 1000, 'swing');
		}
		
		// Set new current
		this.current = newCurrent;
	}
	
	// Go to previous slide
	this.previous = function(autoplay) {
		this.traverse(false, autoplay);
	}
	// Go to next slide
	this.next = function(autoplay) {
		this.traverse(true, autoplay);
	}
	
	// Traverse (Previous/Next) slides
	// previous: direction = 0
	// next: direction = 1
	this.traverse = function(direction, autoplay) {
		// Default autoplay is false
		autoplay = autoplay == true ? true : false;
		
		// Default direction is true (next)
		var targetAnchorIndex = 0;
		if (direction == false) {
			targetAnchorIndex = (this.current == 1) ? this.count - 1 : this.current - 2;
		}
		else {
			targetAnchorIndex = (this.current == this.count) ? 0 : this.current;
		}
		// Swap
		var targetAnchor = $(this.navClass + ' > li > a')[targetAnchorIndex];
		
		this.tabbed.setCurrents(targetAnchor);
		this.swap(targetAnchor.hash, autoplay);
	}
	
	// Stop autoplay
	this.stop = function() {
		if (this.autoplay) {
			this.autoplay = false;
		}
	}
	
	this.construct(args);
}


/* tabbed-v2.js.php */
/*<script>*/
// Requires jquery
// Usage:
/* var tabbed = new Tabbed({navClass: '.tabbed-content ul.nav'
							, currentItem: 1
							//, currentClass: 'current'
							//, tabbedClass: 'tabbed'
							//, toggle: true
							//, noDefaultCurrent: false
							//, callback: functionName
							});
*/
function Tabbed(args) {
	// Constructor
	this.construct = function(args) {
		// Required Parameters
		this.navClass = args.navClass;
		// Optional Parameters
		this.toggle = args.toggle == true ? true : false;
		this.noDefaultCurrent = args.noDefaultCurrent == true ? true : false;
		this.currentItem = args.currentItem > 0 ? args.currentItem : (this.toggle || this.noDefaultCurrent ? 0 : 1);
		this.currentClass = args.currentClass !== undefined ? args.currentClass : 'current';
		this.tabbedClass = args.tabbedClass !== undefined ? args.tabbedClass : 'tabbed';
		this.callback = args.callback;
	
		this.currentNav = false;
		this.currentContent = false;
		
		// Use parent <li>s when applicable
		this.navs = $(this.navClass + ' > li');
		// Don't force anchors to be within <li>
		this.navAnchors = $(this.navClass + ' a[href*="#"]:not([href$="#"])');
		this.contents = [];
		
		// Get content containers based on anchor hashes
		var contentIds = [];
		$(this.navAnchors).each(function() {
			if (this.hash) {
				contentIds.push(this.hash);
			}
		});
		this.contents = $(contentIds.join(', '));
		
		// If not toggle, set current to be first <li> that is expanded
		if (!this.toggle) {
			var firstExpand = $(this.navs).filter('.' + this.currentClass).first();
			var firstExpandIndex = $(this.navs).index(firstExpand);
			if (firstExpandIndex >= 0) {
				this.currentItem = firstExpandIndex + 1;
			}
		}
		
		// Return if contents don't exist
		if (this.contents.length < 1) {
			return;
		}
		
		// Append tabbed class to hide
		$([this.navs, this.navAnchors, this.contents]).each((function(i, el) {
			$(el).addClass(this.tabbedClass);
		}).bind(this));
		
		// Set current class to currentItem's nav & content
		$(this.navAnchors).each((function(i, el) {
			if (i + 1 == this.currentItem) {
				this.setCurrents(el);
			}
		}).bind(this));
		
		this.setEvents();
	}
	
	// Set click events on anchors
	this.setEvents = function() {
		var thisClass = this;
		$(this.navAnchors).click(function() {
			this.blur();
				
			// Clear 'current' class from navs and contents
			// Set current nav and content
			// Apply 'current' class
			thisClass.setCurrents(this);
			return false;
		});
	};
	
	// Remove 'current' class name from navs and contents
	this.clearCurrents = function() {
		$([this.navs, this.navAnchors, this.contents]).each((function(i, el) {
			$(el).removeClass(this.currentClass);
		}).bind(this));
	};
	
	// Add 'current' class name on current nav and content
	this.setCurrents = function(targetAnchor) {
		var target = targetAnchor.hash;
		if (!this.toggle) {
			this.clearCurrents();
		}
		
		// Set current on <li> (parent) nav, <a>, and content
		this.currentNav = $(targetAnchor).parent();
		this.currentContent = $(target);
		$([this.currentNav, targetAnchor, this.currentContent]).each((function(i, el) {
			if (!this.toggle) {
				$(el).addClass(this.currentClass);
			}
			else {
				$(el).toggleClass(this.currentClass);
			}
		}).bind(this));
		
		if(this.callback != null){
			this.callback.call(this, this.currentNav);
		}
	}
	
	this.construct(args);
}

