﻿$(document).ready(function(){
	/* Image preload */
	//jQuery.preLoadImages("button-hover.png", "/wp-content/themes/eorder/images/button-hover.png");
	//jQuery.preLoadImages("error.png.png", "/wp-content/themes/eorder/images/error.png");
	
	/* Fancybox */
	var select = $('a[href$=".bmp"],a[href$=".gif"],a[href$=".jpg"],a[href$=".jpeg"],a[href$=".png"],a[href$=".BMP"],a[href$=".GIF"],a[href$=".JPG"],a[href$=".JPEG"],a[href$=".PNG"],.fancybox');
		select.attr('rel', 'fancybox');
		select.fancybox({
				'titleshow'		: false
				//'titlePosition'	: 'over',
				//'transitionIn'	: 'elastic',
				//'transitionOut'	: 'elastic',
				
			});
	
	/* Sign-up form - change password field type */
	//$('li.password-field input').setAttribute('type') = 'password';	
	
	/* 
	* 1st GALLERY OF HOME PAGE
	*/
	/* This code is executed after the DOM has been completely loaded */
	var totWidthA=0;
	var positionsA = new Array();
	
	$('#slidesA .slideA').each(function(i){
		/* Traverse through all the slides and store their accumulative widths in totWidthA */
		positionsA[i]= totWidthA;
		totWidthA += $(this).width();
		/* The positionsA array contains each slide's commulutative offset from the left part of the container */
		if(!$(this).width()){
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});
	
	/* Change the cotnainer div's width to the exact width of all the slides combined */
	$('#slidesA').width(totWidthA);

	$('#menuA ul li a').click(function(e,keepScroll){
			/* On a thumbnail click */
			$('li.menuItemA').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
				var pos = $(this).parent().prevAll('.menuItemA').length;
				$('#slidesA').stop().animate({marginLeft:-positionsA[pos]+'px'},450);
			/* Start the sliding animation */
				e.preventDefault();
			/* Prevent the default action of the link */
			// Stopping the auto-advance if an icon has been clicked:
			if(!keepScroll) clearInterval(itvlA);
	});
	
	/* On page load, mark the first thumbnail as active */
	$('#menuA ul li.menuItemA:first').addClass('act').siblings().addClass('inact');

	/* Enabling auto-advance. */
	var currentA=1;
	function autoAdvanceA(){
		if(currentA==-1) return false;
		$('#menuA ul li a').eq(currentA%$('#menuA ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		currentA++;
	};
	// The number of seconds that the slider will auto-advance in:
	var changeEvery = 5;
	var itvlA = setInterval(function(){autoAdvanceA()},changeEvery*1000);
	/* End of customizations */
	
	
	/* 
	* 2nd GALLERY OF HOME PAGE
	*/
	/* This code is executed after the DOM has been completely loaded */
	var totWidthB=0;
	var positionsB = new Array();
	
	$('#slidesB .slideB').each(function(i){
		/* Traverse through all the slides and store their accumulative widths in totWidthB */
		positionsB[i]= totWidthB;
		totWidthB += $(this).width();
		/* The positionsB array contains each slide's commulutative offset from the left part of the container */
		if(!$(this).width()){
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});
	
	/* Change the cotnainer div's width to the exact width of all the slides combined */
	$('#slidesB').width(totWidthB);

	$('#menuB ul li a').click(function(e,keepScroll){
			/* On a thumbnail click */
			$('li.menuItemB').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
				var pos = $(this).parent().prevAll('.menuItemB').length;
				$('#slidesB').stop().animate({marginLeft:-positionsB[pos]+'px'},450);
			/* Start the sliding animation */
				e.preventDefault();
			/* Prevent the default action of the link */
			// Stopping the auto-advance if an icon has been clicked:
			if(!keepScroll) clearInterval(itvlB);
	});
	
	/* On page load, mark the first thumbnail as active */
	$('#menuB ul li.menuItemB:first').addClass('act').siblings().addClass('inact');

	/* Enabling auto-advance. */
	var currentB=1;
	function autoAdvanceB(){
		if(currentB==-1) return false;
		$('#menuB ul li a').eq(currentB%$('#menuB ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		currentB++;
	};
	// The number of seconds that the slider will auto-advance in:
	var changeEvery = 7;
	var itvlB = setInterval(function(){autoAdvanceB()},changeEvery*1000);
	/* End of customizations */
	
});

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
