/**
 * Javascript library for template ExtremeMagento
 * @copyright 2007 Quick Solution LTD. All rights reserved.
 * @author Giao L. Trinh <giao.trinh@quicksolutiongroup.com>
 */
 
(function() {

// EM.tools {{{
	
if (typeof BLANK_IMG == 'undefined') 
	var BLANK_IMG = '';

// declare namespace() method
String.prototype.namespace = function(separator) {
  this.split(separator || '.').inject(window, function(parent, child) {
    var o = parent[child] = { }; return o;
  });
};


'EM.tools'.namespace();

EM.tools.roundedCorner = function (selector) {
	$$(selector).each(function(el) {
		$(el).addClassName('em-rounded');
		$(el).insert({
			top: '<span class="tl"> </span><span class="tm"> </span><span class="tr"> </span><span class="ml"> </span><span class="mm"> </span><span class="mr"> </span><span class="bl"> </span><span class="bm"> </span><span class="br"> </span>'
		});
	});
};
EM.tools.roundedCornerTextBox = function () {
	$$('.input-text').each(function(el) {
		if (Element.visible(el) && !el.hasClassName('qty')) {
			$(el).relativize();
			$(el.parentNode).addClassName('em-rounded');
			$(el.parentNode).insert({
				top: '<span class="tl"> </span><span class="tm"> </span><span class="tr"> </span><span class="ml"> </span><span class="mm"> </span><span class="mr"> </span><span class="bl"> </span><span class="bm"> </span><span class="br"> </span>'
			});
		}
	});
};



// EM0008 {{{
	
function decorateCatalogProductView() {
	if (Element.hasClassName(document.body, 'catalog-product-view')) {
		$$('.short-description h2, .product-collateral h2').each(function(el) {
			el.innerHTML = '<span>'+el.innerHTML+'</span>';
		});
	}
}

/*function decorateSlideshow() {
	var $$li = $$('.slideshow ul li');
	if ($$li.length > 0) {
		
		// reset UL's width
		var ul = $$('.slideshow ul')[0];
		var w = 0;
		$$li.each(function(li) {
			w += li.getWidth();
		});
		ul.setStyle({'width':w+'px'});
		
		// private variables
		var previous = $$('.slideshow a.previous')[0];
		var next = $$('.slideshow a.next')[0];
		var num = 3;
		var width = ul.down().getWidth() * num;
		var slidePeriod = 3; // seconds
		var manualSliding = false;
		
		// next slide
		function nextSlide() {
			new Effect.Move(ul, { 
				x: -width,
				mode: 'relative',
				queue: 'end',
				duration: 1.0,
				transition: Effect.Transitions.sinoidal,
				afterFinish: function() {
					for (var i = 0; i < num; i++)
						ul.insert({ bottom: ul.down() });
					ul.setStyle('left:0');
				}
			});
		}
		
		// previous slide
		function previousSlide() {
			new Effect.Move(ul, { 
				x: width,
				mode: 'relative',
				queue: 'end',
				duration: 1.0,
				transition: Effect.Transitions.sinoidal,
				beforeSetup: function() {
					for (var i = 0; i < num; i++)
						ul.insert({ top: ul.down('li:last-child') });
					ul.setStyle({'position': 'relative', 'left': -width+'px'});
				}
			});
		}
		
		
		// bind next button's onlick event
		next.observe('click', function(event) {
			Event.stop(event);
			manualSliding = true;
			nextSlide();
		});
		
		// bind previous button's onclick event
		previous.observe('click', function(event) {
			Event.stop(event);
			manualSliding = true;
			previousSlide();
		});
		
		
		// auto run slideshow
		new PeriodicalExecuter(function() {
			if (!manualSliding) nextSlide();
			manualSliding = false;
		}, slidePeriod);
		
		
	}
}
*/
document.observe("dom:loaded", function() {
	decorateCatalogProductView();
/*	decorateSlideshow();*/
});

document.observe('dom:loaded', function() {
      // reference ID of our show container
      var show = new protoShow('myshow',{
		captions			: true,
	});   
});

// }}}



})();


jQuery(document).ready(function() {
/**Jquery codes*/
jQuery('.minimal-slider').easySlider({
		  auto: true,
		  continuous: true,
		  speed: 800,
		  pause: 10000,
		  controlsFade: true,
		  numeric: true 
	    });
		
function distance(x0, y0, x1, y1) {
				var xDiff = x1-x0;
				var yDiff = y1-y0;
				
				return Math.sqrt(xDiff*xDiff + yDiff*yDiff);
			}
			

				var proximity = 230;
				var iconSmall = 180, iconLarge = 230; //css also needs changing to compensate with size
				var iconDiff = (iconLarge - iconSmall);
				var mouseX, mouseY;
				var dock = jQuery("#dock");
				var dock1 = jQuery("#dock1");
				var dock2 = jQuery("#dock2");
				var animating = false, redrawReady = false;
				
				jQuery(document.body).removeClass("no_js");
			
				//below are methods for maintaining a constant 60fps redraw for the dock without flushing
		
			jQuery(document).bind("mousemove", function(e) {
					if (dock.is(":visible")) {
						mouseX = e.pageX;
						mouseY = e.pageY;
					
						redrawReady = true;
						registerConstantCheck();
					}		
				if (dock1.is(":visible")) {
						mouseX = e.pageX;
						mouseY = e.pageY;
					
						redrawReady = true;
						registerConstantCheck();
					}		

					if (dock2.is(":visible")) {
						mouseX = e.pageX;
						mouseY = e.pageY;
					
						redrawReady = true;
						registerConstantCheck();
					}
				});
		
				
				function registerConstantCheck() {
					if (!animating) {
						animating = true;
						
						window.setTimeout(callCheck,1);
					}
				}
				
				function callCheck() {
					sizeDockIcons();
					
					animating = false;
				
					if (redrawReady) {
						redrawReady = false;
						registerConstantCheck();
					}
				}
				
				//do the maths and resize each icon
				function sizeDockIcons() {
					dock.find("li").each(function() {
						//find the distance from the center of each icon
						var centerX = jQuery(this).offset().left + (jQuery(this).outerWidth()/2.0);
						var centerY = jQuery(this).offset().top + (jQuery(this).outerHeight()/2.0);
						
						var dist = distance(centerX, centerY, mouseX, mouseY);
						
						//determine the new sizes of the icons from the mouse distance from their centres
						var newSize =  (1 - Math.min(1, Math.max(0, dist/proximity))) * iconDiff + iconSmall;
						jQuery(this).find("a").css({width: newSize});
					});
					
					dock1.find("li").each(function() {
						//find the distance from the center of each icon
						var centerX = jQuery(this).offset().left + (jQuery(this).outerWidth()/2.0);
						var centerY = jQuery(this).offset().top + (jQuery(this).outerHeight()/2.0);
						
						var dist = distance(centerX, centerY, mouseX, mouseY);
						
						//determine the new sizes of the icons from the mouse distance from their centres
						var newSize =  (1 - Math.min(1, Math.max(0, dist/proximity))) * iconDiff + iconSmall;
						jQuery(this).find("a").css({width: newSize});
					});
					
					dock2.find("li").each(function() {
						//find the distance from the center of each icon
						var centerX = jQuery(this).offset().left + (jQuery(this).outerWidth()/2.0);
						var centerY = jQuery(this).offset().top + (jQuery(this).outerHeight()/2.0);
						
						var dist = distance(centerX, centerY, mouseX, mouseY);
						
						//determine the new sizes of the icons from the mouse distance from their centres
						var newSize =  (1 - Math.min(1, Math.max(0, dist/proximity))) * iconDiff + iconSmall;
						jQuery(this).find("a").css({width: newSize});
					});
				}
		
		/*Faq scripts*/
		
jQuery('.accordionButtonfaq').click(function()
{
jQuery('.accordionButtonfaq').removeClass('on');
jQuery('.accordionContentfaq').slideUp('normal');
if(jQuery(this).next().is(':hidden')==true)
{
jQuery(this).addClass('on');
jQuery(this).next().slideDown('normal');
}

});

/*Technical support form script*/



jQuery(function($){
    $("#social").delay(6000).queue(function(){
            $(".fbConnectWidgetTopmost").css({"border-style": "hidden"});
	
    });
});

jQuery('#getaquote').submit(function(){				  
		var action = jQuery(this).attr('action');
		jQuery.post(action, { 
			name: jQuery('#fullname').val(),
			email: jQuery('#qemail').val(),
            phone:jQuery('#phone').val(),
            product:jQuery('#product').val(),
            webmessage:jQuery('#webmessage').val()
			},
			function(data){
				jQuery('#getaquote #submit').attr('disabled','');
				jQuery('.response').remove();
				alert(data);
				jQuery('.response').slideDown();
				/*if(data=='Message sent!') $('#contactform').slideUp();*/
			}
		); 
		return false;
	});
		

		});
		
		
		

