var g = {
	tabOverJQ : '#tabOver',
	tabOverId : 'tabOver',
	ajaxSel: 'ajaxSel',
	buyTriggerId: 'enrollBtn',
	compareTrigger: 'compareTrigger',
	stepsTrigger: 'stepsTrigger',
	satisfactionTrigger: 'satisfactionTrigger',
	faqTrigger: 'faqTrigger',
	compareOnlineTrigger: 'compareOnlineTrigger',
	featuresTrigger: 'featuresTrigger',
	tabLeft : '0px'
};

// INITIALIZATION ***********************************
jQuery(function($) {

$(document.body).removeClass("jsOff").addClass("jsOn");
setWidthClass();

if (getBodyId()==='home') {
		$('<span id="'+g.tabOverId+'"></span>').appendTo($('#section1'));
		g.tabOverJQ = $('#'+g.tabOverId);
		g.tabOverJQ.css('left',g.tabLeft);
		$('#tabs li').hover(
			function () { 
			var cl = $(this).attr('class'), that = this,
				loaded = $('#section1').find('div.tab:visible');				
			
			g.tabLeft = $(that).css('left');
			g.tabOverJQ.css('left',g.tabLeft);
			loaded.hide();
				$('#'+cl).show();}
		)
		.click( function() { 
			var cl = $(this).attr('class'), that = this,
				loaded = $('#section1').find('div.tab:visible');				
			
			g.tabLeft = $(that).css('left');
			g.tabOverJQ.css('left',g.tabLeft);
			loaded.hide();
				$('#'+cl).show();
			
		});
		if (window.location.hash) {
		$('#tabs li.'+window.location.hash.substring(1)).trigger('click');
		}
}

//***START AJAX ROUTINE    
//instantiate the ajax ctners holder, to return global var homeAjaxCtnersHolder which holds ajax ctners (each ctner ==  property-obj) 
//CSS classes: oneAjaxCtner, ajaxed
if ($(document.body).hasClass('ajaxed')) {
lsatAjaxCtnersHolder = pageAjaxCtnersConstructor();
//for all pages
lsatAjaxCtnersHolder.addCtner( [
	{
		ctnerClassName: 'section3Mid', 
		parentCtnerId: 'section3ContWrap'
	}
	]);
var contentParamsConstructor = function(args) {
		var that = {};
		that.ctnerClassName = args.ctnerClassName;
		that.initContentId = args.initContentId;
		that.fallBackContentId = args.fallBackContentId;
		that.ctnersHolder = lsatAjaxCtnersHolder;
		that.pathStart= 'texts/'+args.ctnerClassName+'/';
		that.pathEnd= '.html';	
		return that;
	}
	
var contentParams,initContentId = undefined, args = {};
	
	// read location extentions, define the init content
	if (location.toString().indexOf('?p') > -1) {
		initContentId = amdLib.getUrlSearchArgs().p;
	} else if (location.toString().indexOf('#') > -1) {	
		initContentId = getStrFromHrefHash(location);
	} else {
		initContentId = ''; //define here if needed, or leave empty to load the first div already included in html
	}

switch(getBodyId()) {
case 'course': 
	//define all ajax containers, pass all of them as separate objs of one whole array
	//constructor takes 4 params, 3 are !null, while fixed is for ctner with fixed, not dynamic content,and can be omitted
	lsatAjaxCtnersHolder.addCtner( [
	{
		ctnerClassName: 'course', 
		parentCtnerId: 'section3Mid', 
		ctnerId:'oneCourseInfo'
	}
	]);	

	args = {
		initContentId: initContentId,
		fallBackContentId: 'Unique_Structure',
		ctnerClassName: 'course',
		ctnersHolder: lsatAjaxCtnersHolder
		};
	break;
case 'why':
	lsatAjaxCtnersHolder.addCtner( [
	{
		ctnerClassName: 'why_us', 
		parentCtnerId: 'section3Mid', 
		ctnerId:'oneWhyUs'
	}
	]);	

	args = {
		initContentId: initContentId,
		fallBackContentId: 'Happy_Students',
		ctnerClassName: 'why_us',
		ctnersHolder: lsatAjaxCtnersHolder
		};
	break;
}
	//contruct params for ajax ctner and content builders	
	var lsatAjax = lsatAjaxContentBuilder( contentParamsConstructor( args ) );
	lsatAjax.init();
	
};// END AJAX ROUTINE

// INITIALIZE ENROLL/GOOGLE BLOCK
if (document.getElementById(g.buyTriggerId)) {
	$('#buyJsOff').remove();

	$.get('code/google_checkout.html', function(data) {
		var $enroll = $('#enroll');
		$enroll.append(data);
		$buyBtn = $('#BB_BuyButtonForm');
		if (getBodyId()==='home') {
			$('#enrollBtn').toggle(
				function () {
					$('#section1').css({'overflow':'visible','z-index':'2'});
					$buyBtn.slideDown('slow');
				  },
				function () {
					$buyBtn.slideUp('slow', function() {
						$('#section1').css({'overflow':'hidden','z-index':'1'});
					})
				}
			)
		  } else {
			  $('#enrollBtn').toggle(
				  function () {
					$enroll.css('width','300px');
					$buyBtn.slideDown('slow', function() {
					$enroll.css('border','1px solid #ddd');
						});
				  },
				function () {
					$enroll.css('border','1px solid #fff');
					$buyBtn.slideUp('slow', function() {
						$enroll.css('width','225px');
					})
				}
			  )
		  }  
	})
};
// INITIALIZE POP UPS
if (document.getElementById(g.compareTrigger)) {
	var comparePopUp = {
		triggerId: g.compareTrigger,
		popup: 'comparePopUp',
		ctner: 'compareCtner'
	}
	popUpBuilder(comparePopUp);
    $.preload( ['images/compareImg.png'] );
 };
if (document.getElementById(g.compareOnlineTrigger)) {
	var compareOnlinePopUp = {
		triggerId: g.compareOnlineTrigger,
		popup: 'compareOnlinePopUp',
		ctner: 'compareOnlineCtner'
	}
	popUpBuilder(compareOnlinePopUp);
    $.preload( ['images/compareOnlineImg.png'] );
 }; 
if (document.getElementById(g.stepsTrigger)) {
	var stepsPopUp = {
		triggerId: g.stepsTrigger,
		popup: 'stepsPopUp',
		ctner: 'stepsCtner'
	}
	popUpBuilder(stepsPopUp);
    $.preload( ['images/stepsImg.png'] );
};
if (document.getElementById(g.satisfactionTrigger)) {
	var satisfactionPopUp = {
		triggerId: g.satisfactionTrigger,
		popup: 'satisfactionPopUp',
		ctner: 'satisfactionCtner'
	}
	popUpBuilder(satisfactionPopUp);
    $.preload( ['images/satisfactionImg.png'] );
};
if (document.getElementById(g.faqTrigger)) {
	var faqPopUp = {
		triggerId: g.faqTrigger,
		popup: 'faqPopUp',
		ctner: 'faqCtner'
	}
	popUpBuilder(faqPopUp);
};
if (document.getElementById(g.featuresTrigger)) {
	var featuresPopUp = {
		triggerId: g.featuresTrigger,
		popup: 'featuresPopUp',
		ctner: 'featuresCtner'
	}
	popUpBuilder(featuresPopUp);
    $.preload( ['images/features.png'] );
};

// INITIALIZE CONTACT FORM
if (getBodyId()==='contact') {
	$('noscript').remove();	 
	prepareContactForm();
};

// REMOVE HREFS TO SELF
$('a[href]').each( function() { 
	var t = $(this);
	if (t.parent().hasClass(getBodyId())) { 
		t.removeAttr('href'); 
	}
});
//START IE
/*@cc_on
//START IE6
if (parseInt(jQuery.browser.version)===6) { 
if (getBodyId()==='home') {

	$('#tabs li').unbind('hover');
	$('#tabs li').unbind('click');
		$('#tabs li').hover(
			function () {
				$(this).addClass('ieover');
			  }, function () {
				$(this).removeClass('ieover');
			  }
		)
		.click( function() { 
			var cl = $(this).attr('class');
			cl = cl.split(' ')[0];
			var loaded = $('#section1').find('div.tab:visible');	
			//if (cl === loaded.attr('id')) { return; }
			loaded.css('display','none'); 
			$('#'+cl).css('display','block');
		});
	}
	$('a.am-hoverShw').append('<span></span>');
	$('#enrollBtn').hover(
		function () {
			$(this).addClass('ieover');
		  }, function () {
			$(this).removeClass('ieover');
		  }
	)
	$('#logoMenu a[href]').hover(
		function () {
			$(this).addClass('ieover');
		  }, function () {
			$(this).removeClass('ieover');
		  }
	)
}//end IE6
@*/
//end IE
	
});//end init
// FUNCTIONS ***********************************
var popUpBuilder = function(obj) {

	var triggerJQ = $('#'+obj.triggerId),  //the whole module is called only if this exists
	popUpCtner = document.getElementById(obj.popup) || undefined,
	popUpCtnerJQ;
	
	if (!popUpCtner) {
		triggerJQ.one("click", function(e) { 
			e.preventDefault();
			creatCtner();
			if(obj.popup === 'faqPopUp') {
				var faqCtnerJQ = $('#'+obj.ctner);
				$.get('texts/faq/faq.html', function(data){
					faqCtnerJQ.prepend(data);
					enableFAQ(faqCtnerJQ);
					instantiatePopUpObj();
					attachJModal();
					triggerJQ.trigger('click');
				})
			} else {
				instantiatePopUpObj();
				attachJModal();
				triggerJQ.trigger('click');
			}
		})
	} else {
		instantiatePopUpObj();
		attachJModal();
	}
	
	var creatCtner = function() {
		var insertStr = '<div id="'+obj.popup+'" class="jqmWindow">'+
						'<div id="'+obj.ctner+'" class="jqmContent">'+
						'<div class="jqmClose"></div>'+
						'</div></div>';
		$(insertStr).appendTo($(document.body));
	};
	
	var attachJModal = function() {
		//start IE
		if ( $.browser.msie  && (parseInt(jQuery.browser.version)===6)) {
			
			popUpCtnerJQ.jqm({
			  trigger:'#'+obj.triggerId,
			  onShow: function(h) {
				/* callback executed when a trigger click. Show notice */
				h.w.css('opacity',1).show();
				//h.o.show();
				if(getPageScroll().yScroll>0) {
					$.scrollTo('0', {duration:400 });
					}
				},
			  onHide: function(h) {
				/* callback executed on window hide. Hide notice, overlay. */
				h.w.hide(100,function() { 
					if(h.o) { h.o.remove(); }
					}); 
				} 
			});
		} else {
			popUpCtnerJQ.jqm({
			  trigger:'#'+obj.triggerId,
			  onShow: function(h) {
				/* callback executed when a trigger click. Show notice */
				h.w.css('opacity',1).slideDown();
				h.o.fadeTo('slow',.6);
				if(getPageScroll().yScroll>0) {
					$.scrollTo('0', {duration:400 });
					}
				},
			  onHide: function(h) {
				/* callback executed on window hide. Hide notice, overlay. */
				h.w.slideUp("slow",function() { if(h.o) h.o.remove(); }); } 
			});
		}
    }
    var instantiatePopUpObj = function() {
	   popUpCtnerJQ = $('#'+obj.popup);
		popUpCtnerJQ.click(function(e) {
			if($(e.target).hasClass('jqmWindow')) {
				popUpCtnerJQ.jqmHide();
			}
		})
    }
    var enableFAQ = function(faqCtnerJQ) {
		var selClass = 'faqSel';
		faqCtnerJQ.find('.q').click(function() {
			var parentJQ = $(this).closest('.oneFAQ');
			if (parentJQ.hasClass(selClass)) { 
				parentJQ.removeClass(selClass).find('.a').slideUp('slow');
			} else {
				var elm = faqCtnerJQ.find('.'+selClass);
				if(!elm[0]) {
					parentJQ.addClass(selClass).find('.a').slideDown(300, function() {
						   if (!jQuery.support.opacity) { 
							   this.style.removeAttribute('filter');
							   document.getElementById('faqPopUp').style.removeAttribute('filter');
						   }
						});
				} else {
					faqCtnerJQ.find('.'+selClass).removeClass(selClass).find('.a').slideUp(300, function() {
						parentJQ.addClass(selClass).find('.a').slideDown(300, function() {
						   if (!jQuery.support.opacity) { 
							   this.style.removeAttribute('filter');
							   document.getElementById('faqPopUp').style.removeAttribute('filter');
						   }
						});
					})
				}
			}
		})
		
		if ( $.browser.msie  && (parseInt(jQuery.browser.version)===6)) { 
			faqCtnerJQ.find('.q').hover(
				function () {
					$(this).addClass('ieover');
				  }, function () {
					$(this).removeClass('ieover');
				  }
			)
		}
	}
    
}

var lsatAjaxContentBuilder = function(paramsClass) {

	// augment paramsClass if needed
	var paramsInstance = { };
	
	//define ajax loading triggers, 
	//ONLY if they are static from the beginning till end!!!
	paramsClass.ajaxLoadTriggers = $('#ajaxedContents').find('a');
	
	// create instance from the class constructor:
	var that = ajaxContentConstructor(paramsClass,paramsInstance);
	
	//add load event! it passes id string picked from clicked elm
	that.addLoadEvent = (function() {
		paramsClass.ajaxLoadTriggers.click( function(e) {
				e.preventDefault();	
				that.loadEventHandler($(this));
		});
	})();
	//add close/change_content event
		
	
	//redefine the click event for reloading of this content block
	//that.redefineClick();
	return that;
}

var ajaxContentConstructor = function(paramsClass,paramsInstance) {
	//This is Class constructor
	/* 
	HTML: loading content block html name == it's top div's id == id passed by clicked elm
	
	CSS define: .oneAjaxCtner { display: none; }, where class="oneAjaxCtner" for contentCtnerId
	should be added to the wrapping ajax parent element, to keep it invisible on page initial load
	
	-----paramsClass----- passed to constructor
	contentCtnerId | !null : pass plain id; 
	params.initContentId | null : changable ajax content, id = file name
		if not passed, first html div is found and loaded
	
	-----paramsInstance---- added for specific case
	loadCallback
	
	*/
	var contentCtnerId = paramsClass.ctnersHolder[paramsClass.ctnerClassName].ctnerId,
		contentCtnerIdJ = '#'+contentCtnerId,
		contentCtnerJQ = $('#'+contentCtnerId),
		ctnersHolder = paramsClass.ctnersHolder,
		ajaxLoadTriggers = paramsClass.ajaxLoadTriggers,
		currentContent,
		nextContent;
		
	var loadCallback = paramsInstance.loadCallback || function() {};
	
	//check if contentCtnerId exists, if not -- create & add it to DOM and redefine var
	var checkExistCtner = function() { 
		try {
			if (!contentCtnerJQ[0]) { 
				if (paramsClass.addToDOMCtnerStr) {	
					$(paramsClass.addToDOMCtnerStr).appendTo(ctnersHolder[paramsClass.ctnerClassName].parentCtnerJQ());
				} else {
					$('<div id="' + contentCtnerId + '"></div>').appendTo(ctnersHolder[paramsClass.ctnerClassName].parentCtnerJQ());
				}
				contentCtnerJQ = $('#'+contentCtnerId); 
			}
		}	
		catch(e) {
			alert(e.message);
		}
	};

	//ignore the next 2 steps if the contents are unchangable
	if (!ctnersHolder[paramsClass.ctnerClassName].fixed) {		
		
		//check if the contentCtner already in DOM
		checkExistCtner();
		// get array of all first-level divs with id within contentCtner
		//EXECUTES on being called as constructor!!!
		var loadedContentIdList = (function() {
			var a = [];
			$(contentCtnerIdJ+ ' > div[id]').each(function() {
				a.push(this.id);
				$(this).hide(); 
			})
			//console.log('297: '+a);
			return a;
		})();
	}
	
	// fires once, on load	
	var init = function() {
	
		//	if params.initContentId is supplied, show or load_and_show it
		if (paramsClass.initContentId) {
			
			//console.log('304: '+paramsClass.initContentId);
			if($.inArray(paramsClass.initContentId,loadedContentIdList)>-1) {
				currentContent = contentConstr(false,paramsClass.initContentId);
			} else {
				nextContent = contentConstr(false,paramsClass.initContentId);
			}
		//params.initContentId is NOT supplied: loads first div in parent folder
		} else { 
			if (loadedContentIdList.length>0) {
				currentContent = contentConstr(false,loadedContentIdList[0]);
			} else {
				throw new Error('Init load content is undefined!');
				return;
			}
		};		
		loadContentOnInit();
	};
	var loadContentOnInit = function() { 
		if(currentContent) {
				currentContent.objJQ().show();
				contentCtnerJQ.fadeIn('fast', function() {
						if (!jQuery.support.opacity) { 
						this.style.removeAttribute('filter'); }
					});
				setClassLoadedTrigger(currentContent.id);
		} else {
			$.ajax({  
				url: nextContent.path, 
				success: function (html) { 
					contentCtnerJQ.append(html).fadeIn('fast', function() {
						   if (!jQuery.support.opacity) { this.style.removeAttribute('filter'); }
						});
					loadedContentIdList.push(nextContent.id);
					if (nextContent.clickedJQ) {
						currentContent = contentConstr(nextContent.clickedJQ);
					} else {
						currentContent = contentConstr(false,nextContent.id);
					}
					setClassLoadedTrigger(nextContent.id);
					loadCallback(); //should stay inside here! defined in the instance constructor
				},
				error: function (xhr, ajaxOptions, thrownError) { 
				  if(xhr.status == 404) { 
				    nextContent = contentConstr(false,loadedContentIdList[0]);
					loadContentOnInit();
					window.location.hash = "";
					// if no content originally in DOM, add paramsClass.fallBackContentId
				  } 
				  else { 
				    // default error 
				  } 
				}
			}) // end ajax
		}
	}
	
	// constructor for content object, has instances of currentContent and nextContent
	var contentConstr = function(clickedJQ,id) {		
		var that = {};
		that.clickedJQ = clickedJQ;
		if (id) {
			that.id = convertId(id);
		} else {
			that.id = convertId(clickedJQ.text());
		}
		that.objJQ = function() { return $('#'+that.id) };	
		that.path = paramsClass.pathStart+that.id+paramsClass.pathEnd;
		//sthat.show = showObj;
		return that;
	};
	// tied to addLoadEvent in the instance constructor
	var loadEventHandler = function(clickedJQ) {		
		
		// return when repeated click on same and same ajax container in action
		if (clickedJQ.hasClass(g.ajaxSel) && contentCtnerJQ.is(':visible')) { return; }
		
		nextContent = contentConstr(clickedJQ);
		
		loadContent();
		
		ajaxLoadTriggers.filter('.'+g.ajaxSel).removeClass(g.ajaxSel);
		clickedJQ.addClass(g.ajaxSel);
	};
	
	var loadContent = function() { 
		if (contentCtnerJQ.is(':visible')) { //same ajax container in action

			 if ( $.inArray(nextContent.id,loadedContentIdList)===-1 ) {
				// if the next content needs to be loaded
				//console.log('372: '+nextContent.id);
				$.get(nextContent.path, function(data){
					contentCtnerJQ.fadeOut('fast', function() {
						currentContent.objJQ().hide();
						contentCtnerJQ.append(data).fadeIn('fast', function() {
						   if (!jQuery.support.opacity) { this.style.removeAttribute('filter'); }
						});
						loadedContentIdList.push(nextContent.id);
						currentContent = contentConstr(nextContent.clickedJQ);
						loadCallback(); 
					});
				})
			} else { // if the next content is already loaded
				currentContent.objJQ().fadeOut('fast', function() {
					nextContent.objJQ().fadeIn('fast', function() {
						   if (!jQuery.support.opacity) { this.style.removeAttribute('filter'); }
						});
					currentContent = contentConstr(nextContent.clickedJQ);
					loadCallback(); 
				});
			}
		} else { //another ajax container is active, fade it out first
			ctnersHolder[contentCtnerId].parentCtnerJQ().find('.oneAjaxCtner:visible')
			.fadeOut('fast', function() {
				if ( $.inArray(nextContent.id,loadedContentIdList)===-1 ) {
				// if the next content needs to be loaded
				//console.log('372: '+nextContent.id);
					$.get(nextContent.path, function(data){
						currentContent.objJQ().hide();
						contentCtnerJQ.append(data).fadeIn('fast');
						loadedContentIdList.push(nextContent.id);
						currentContent = contentConstr(nextContent.clickedJQ);
						loadCallback(); 
					});
				
				} else { // if the next content is already loaded
					if ( currentContent.id !== nextContent.id) {
						currentContent.objJQ().hide();
						nextContent.objJQ().show();
					}
					contentCtnerJQ.fadeIn('fast');
					currentContent = contentConstr(nextContent.clickedJQ);
					loadCallback();					
				}
			}) // end of active ajax Ctner fade-out
		}
	};
	
	var convertId = function(id) {
		var n = replaceInStr(" & ","_",id);
		n = replaceInStr(" ","_",n);
		return n;
	}
	var setClassLoadedTrigger = function(id) {
		var loaded = convertId(id);
		ajaxLoadTriggers.each(function() {
			if (convertId($(this).text()) === loaded) {
				$(this).addClass(g.ajaxSel);
			}
		})	
	}
	var that = {};
	that.init = init;
	//that.redefineClick = redefineClick;
	that.loadEventHandler = loadEventHandler; // return those used in paramsInstance
	return that;
};
var pageAjaxCtnersConstructor = function() {
	var ctnerHolder = {};
	var addCtner = function(paramArr) {
		for(var i=0; i<paramArr.length; i++) {
			ctnerHolder[paramArr[i].ctnerClassName] = {
				parentCtnerId: paramArr[i].parentCtnerId,
				parentCtnerJQ: function() { return $('#'+this.parentCtnerId); },
				ctnerId: paramArr[i].ctnerId,
				ctnerJQ: function() { return $('#'+this.ctnerId); },
				fixed: paramArr[i].fixed || undefined
			};
		}
	}
	ctnerHolder.addCtner = addCtner;
	return ctnerHolder;
	//add checking that parentCtner exists!
};

//GENERAL HELPER FUNCTIONS

function setWidthClass() {
		if (screen.availHeight > 768) {
			$(document.body).removeClass('w1024').addClass("w1280");
		}
	}
function getBodyId() {
		return document.body.getAttribute('id');
	};

function getStrFromHrefHash(h) {
		if(typeof h === 'object') { h = h.href };
		return h.split('#')[1];
	};
function getStrFromHrefSearch(h) {
		if(typeof h === 'object') { h = h.href };
		return h.split('?p=')[1];
	};

function prepareContactForm() {

	if (jQuery.browser.msie) {
		$('#amcf_submitBtn').hover(function() { 
		$(this).toggleClass("over"); },function() {
		$(this).toggleClass("over"); });
		$('input').focus(function() {$(this).addClass('ieFocus')});
		$('input').blur(function() {$(this).removeClass('ieFocus')});
		$('textarea').focus(function() {$(this).addClass('ieFocus')});
		$('textarea').blur(function() {$(this).removeClass('ieFocus')})
	};
		$("#amcf_name, #amcf_note, #amcf_email").focus( function() { 
			if($(this).next().is(':visible')) { $(this).next().hide('slow')}
		});
		var options = { 
		beforeSubmit: validate, 
		success: showResponse 
		};
		$('#am_cf').ajaxForm(options);
};

function validate(formData, jqForm, options) { 
	var form = jqForm[0];
	var err= false;
	if (!form.amcf_name.value) { $("#amcf_nameErr").show(); err = true;}
	if (form.amcf_note.value.length<6) { $("#amcf_noteErr").show(); err = true;}
	if (emailCheck(form.amcf_email.value)) { $("#amcf_emailErr").show(); err = true; }
	if (err) return false;
};

function showResponse()  {
	$('#am_cf').unbind('submit'); $('#amcf_submitBtn').unbind('click');
	$('#am_cf').hide('slow',function() {
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) != 6) {
		$('div.amcf_response').show();
	} else {
		$('div.amcf_response').fadeIn('slow');
	}
	});
};

function emailCheck(value) {
	return !value.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i);
};

function replaceInStr(a,b,c) {
	var re = new RegExp(a , "g");
	return c.replace(re, b);
};
function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {// Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	var arrayPageScroll = {'xScroll':xScroll,'yScroll':yScroll};
	return arrayPageScroll;
};
(function( $ ){

	var $preload = $.preload = function( original, settings ){
		if( original.split )//selector
			original = $(original);

		settings = $.extend( {}, $preload.defaults, settings );
		var sources = $.map( original, function( source ){
			if( !source ) 
				return;//skip
			if( source.split )//URL Mode
				return settings.base + source + settings.ext;
			var url = source.src || source.href;//save the original source
			if( typeof settings.placeholder == 'string' && source.src )//Placeholder Mode, if it's an image, set it.
				source.src = settings.placeholder;
			if( url && settings.find )//Rollover mode
				url = url.replace( settings.find, settings.replace );
			return url || null;//skip if empty string
		});

		var data = {
			loaded:0,//how many were loaded successfully
			failed:0,//how many urls failed
			next:0,//which one's the next image to load (index)
			done:0,//how many urls were tried
			//found:false,//whether the last one was successful
			total:sources.length//how many images are being preloaded overall
		};
		
		if( !data.total )//nothing to preload
			return finish();
		
		var imgs = '<img/>',//ensure one
			thres = settings.threshold;//save a copy
		
		while( --thres > 0 )//it could be oddly negative
			imgs += '<img/>';
		imgs = $(imgs).load(handler).error(handler).bind('abort',handler).each(fetch);
		
		function handler( e ){
			data.found = e.type == 'load';
			data.image = this.src;
			var orig = data.original = original[this.index];
			data[data.found?'loaded':'failed']++;
			data.done++;
			if( settings.placeholder && orig.src )//special case when on placeholder mode
				orig.src = data.found ? data.image : settings.notFound || orig.src;
			if( settings.onComplete )
				settings.onComplete( data );
			if( data.done < data.total )//let's continue
				fetch( 0, this );
			else{//we are finished
				if( imgs.unbind )//sometimes IE gets here before finishing line 84
					imgs.unbind('load').unbind('error').unbind('abort');//cleanup
				imgs = null;
				finish();
			}
		};
		function fetch( i, img, retry ){
			if( $.browser.msie && data.next && data.next % $preload.gap == 0 && !retry ){//IE problem, can't preload more than 15
				setTimeout(function(){ fetch( i, img, true ); }, 0);
				return false;
			}
			if( data.next == data.total ) return false;//no more to fetch
			img.index = data.next;//save it, we'll need it.
			img.src = sources[data.next++];
			if( settings.onRequest ){
				data.image = img.src;
				data.original = original[data.next-1];
				settings.onRequest( data );
			}
		};
		function finish(){
			if( settings.onFinish )
				settings.onFinish( data );
		};
	};

	// each time we load this amount and it's IE, we must rest for a while, make it lower if you get stack overflow.
	$preload.gap = 14; 

	$preload.defaults = {
		threshold:2,//how many images to load simultaneously
		base:'',//URL mode: a base url can be specified, it is prepended to all string urls
		ext:'',//URL mode:same as base, but it's appended after the original url.
		replace:''//Rollover mode: replacement (can be left empty)
		/*
		find:null,//Rollover mode: a string or regex for the replacement
		notFound:''//Placeholder Mode: Optional url of an image to use when the original wasn't found
		placeholder:'',//Placeholder Mode: url of an image to set while loading
		onRequest:function( data ){ ... },//callback called every time a new url is requested
		onComplete:function( data ){ ... },//callback called every time a response is received(successful or not)
		onFinish:function( data ){ ... }//callback called after all the images were loaded(or failed)
		*/
	};

	$.fn.preload = function( settings ){
		$preload( this, settings );
		return this;
	};

})( jQuery );
/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 9/11/2008
 * @author Ariel Flesler
 * @version 1.4
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
(function(h){var m=h.scrollTo=function(b,c,g){h(window).scrollTo(b,c,g)};m.defaults={axis:'y',duration:1};m.window=function(b){return h(window).scrollable()};h.fn.scrollable=function(){return this.map(function(){var b=this.parentWindow||this.defaultView,c=this.nodeName=='#document'?b.frameElement||b:this,g=c.contentDocument||(c.contentWindow||c).document,i=c.setInterval;return c.nodeName=='IFRAME'||i&&h.browser.safari?g.body:i?g.documentElement:this})};h.fn.scrollTo=function(r,j,a){if(typeof j=='object'){a=j;j=0}if(typeof a=='function')a={onAfter:a};a=h.extend({},m.defaults,a);j=j||a.speed||a.duration;a.queue=a.queue&&a.axis.length>1;if(a.queue)j/=2;a.offset=n(a.offset);a.over=n(a.over);return this.scrollable().each(function(){var k=this,o=h(k),d=r,l,e={},p=o.is('html,body');switch(typeof d){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(d)){d=n(d);break}d=h(d,this);case'object':if(d.is||d.style)l=(d=h(d)).offset()}h.each(a.axis.split(''),function(b,c){var g=c=='x'?'Left':'Top',i=g.toLowerCase(),f='scroll'+g,s=k[f],t=c=='x'?'Width':'Height',v=t.toLowerCase();if(l){e[f]=l[i]+(p?0:s-o.offset()[i]);if(a.margin){e[f]-=parseInt(d.css('margin'+g))||0;e[f]-=parseInt(d.css('border'+g+'Width'))||0}e[f]+=a.offset[i]||0;if(a.over[i])e[f]+=d[v]()*a.over[i]}else e[f]=d[i];if(/^\d+$/.test(e[f]))e[f]=e[f]<=0?0:Math.min(e[f],u(t));if(!b&&a.queue){if(s!=e[f])q(a.onAfterFirst);delete e[f]}});q(a.onAfter);function q(b){o.animate(e,j,a.easing,b&&function(){b.call(this,r,a)})};function u(b){var c='scroll'+b,g=k.ownerDocument;return p?Math.max(g.documentElement[c],g.body[c]):k[c]}}).end()};function n(b){return typeof b=='object'?b:{top:b,left:b}}})(jQuery);
(function($) {
$.fn.jqm=function(o){
var p={
overlay: 50,
overlayClass: 'jqmOverlay',
closeClass: 'jqmClose',
trigger: '.jqModal',
ajax: F,
ajaxText: '',
target: F,
modal: F,
toTop: F,
onShow: F,
onHide: F,
onLoad: F
};
return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
if(p.trigger)$(this).jqmAddTrigger(p.trigger);
});};

$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
$.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});};
$.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});};

$.jqm = {
hash:{},
open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);
 if(c.modal) {if(!A[0])L('bind');A.push(s);}
 else if(c.overlay > 0)h.w.jqmAddClose(o);
 else o=F;

 h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
 if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}

 if(c.ajax) {var r=c.target||h.w,u=c.ajax,r=(typeof r == 'string')?$(r,h.w):$(r),u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u;
  r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
 else if(cc)h.w.jqmAddClose($(cc,h.w));

 if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);	
 (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
},
close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
 if(A[0]){A.pop();if(!A[0])L('unbind');}
 if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
 if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
},
params:{}};
var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),F=false,
i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
 if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});};
})(jQuery)