//hoverFlow
(function($){$.fn.hoverFlow=function(c,d,e,f,g){if($.inArray(c,['mouseover','mouseenter','mouseout','mouseleave'])==-1){return this}var h=typeof e==='object'?e:{complete:g||!g&&f||$.isFunction(e)&&e,duration:e,easing:g&&f||f&&!$.isFunction(f)&&f};h.queue=false;var i=h.complete;h.complete=function(){$(this).dequeue();if($.isFunction(i)){i.call(this)}};return this.each(function(){var b=$(this);if(c=='mouseover'||c=='mouseenter'){b.data('jQuery.hoverFlow',true)}else{b.removeData('jQuery.hoverFlow')}b.queue(function(){var a=(c=='mouseover'||c=='mouseenter')?b.data('jQuery.hoverFlow')!==undefined:b.data('jQuery.hoverFlow')===undefined;if(a){b.animate(d,h)}else{b.queue([])}})})}})(jQuery);
//trim
String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, ''); }
//EqualHeights
$.fn.equalHeights=function(b){$(this).each(function(){var a=0;$(this).children().each(function(i){if($(this).height()>a){a=$(this).height()}});if($.browser.msie&&$.browser.version==6.0){$(this).children().css({'height':a})}$(this).children().css({'min-height':a})});return this};
//Max, Min, Sum
Array.prototype.max = function(){return Math.max.apply({},this);}
Array.prototype.min = function(){return Math.min.apply({},this);}
Array.prototype.sum = function(){for(var i=0,sum=0;i<this.length;sum+=this[i++]);return sum;}



$(document).ready(function() {

	//bottom logos aninmation
	var visible_logos = 5;
	var logos = $('#logos');
	var lis = $('li', logos);
	if(lis.length > visible_logos){
		//$(window).bind("load", function(){
			//$.getScript('/media/js/jquery/jquery.carousel.js', function() {
				var width_contanier = logos.width();
				var widths = lis.map(function(){return $(this).width();}).get();
				lis.width(widths.max());
				logos.jCarouselLite({
				   visible: visible_logos,
				   circular: true,
				   vertical: false,
				   auto: 7000, 
				   speed: 1000,
				   scroll: 2
				});
				logos.width(width_contanier);
				//$('ul', logos).width(widths.sum());
			//});
		//});
	}
	
	//hexagon menu
	var _offer = $('#offer');	
	try{
		if(window.location.pathname.search(/^\/products\/\d+\/.*/) == 0){
			var _url = window.location.pathname.split('/').slice(0,3).join('/');
			_offer.find('a[href^="'+_url+'"]').addClass('active').parent('li').addClass('active');
		}
	}catch(e){}
	
	if(!($.browser.msie && $.browser.version <= 6)){
		_offer.find('a').each(function() {
			var _a = $(this);
			var span = $("<span/>", {
				text: _a.text(), 
				title: _a.text(), 
				click: function(){window.location = _a.attr('href');}
			});
			_a.text('').after(span);
		});
	}
	if(!$.browser.msie){
		_offer.find('li').hover(function(e) {
				var _this = $(this);
				_this.children('a').hoverFlow(e.type, { opacity: 0.3 }, 'fast');
				if(!_this.hasClass('active'))
					_this.children('span').stop().animate({ opacity: 1 }, 'fast');
			}, function(e) {
				var _this = $(this);
				_this.children('a').hoverFlow(e.type, { opacity: 1 }, 'slow');
				if(!_this.hasClass('active'))
					_this.children('span').stop().animate({ opacity: 0 }, 'slow');
		});
	}
	
	//EqualHeights
	var equal_heights = function(){$('#wrap_center .container').equalHeights();}
	equal_heights();
	$(window).bind("load", equal_heights);
});
