(function($){
$(document).ready(function() {
	
	/* Breadcrumbs height */

	bwidth = 0;
	$("#breadcrumbs").children().each(function() {
		bwidth += $(this).width();
	});
	if(bwidth - $("#breadcrumbs").width() > 0) $("#breadcrumbs").height(35);
	
	/* END Breadcrumbs height */
	
	/* MAIN MENU */
	
	var tempW=0;
	var tempWE=0;
	$('#menu-main>li').each(function(){
		tempW=tempW+$(this).width();
	});
	tempW = parseInt(tempW);
	
	tempWE=($('#menu-main').width()-tempW)/($('#menu-main>li').size()-1);
	$('#menu-main>li').css('margin-right',tempWE+'px');
	$('#menu-main>li:last').css('margin-right','0px');
	
	x = 0;
	$('#menu-main li.bighover ul li').each(function(){
		$(this).evenIfHidden(function(liElement){
			x+=liElement.width();
		});
		/*x=x+$(this).width();*/
	});
	
	if($.browser.msie === true && $.browser.version == '7.0')
	{
		$('#menu-main li.bighover ul').width(x+80);
	}
	else
	{
		$('#menu-main li.bighover ul').width(x+150);
	}
	
	
	x = 0;
	$('#menu-main li.hover ul li').each(function(){
		$(this).evenIfHidden(function(liElement){
			x+=liElement.width();
		});
		/*x=x+$(this).width();*/
	});
	if($.browser.msie === true && $.browser.version == '7.0')
	{
		$('#menu-main li.hover ul').width(x);
	}
	else
	{
		$('#menu-main li.hover ul').width(x+110);
	}
		
		
	/*$('#menu-main li.bighover ul li.top').width($('#menu-main li.bighover ul').width()-21);
	$('#menu-main li.bighover ul li.bottom').width($('#menu-main li.bighover ul').width()-21);
	$('#menu-main li.bighover ul li.bottom').css('top',$('#menu-main li.bighover ul').height());
	$('#menu-main li.bighover ul li.left, #menu-main li.bighover ul li.right').height($('#menu-main li.bighover ul').height()+10);
	$('#menu-main li.bighover ul li.right').css('margin-left', $('#menu-main li.bighover ul').width()-1);
	$('#menu-main li.bighover ul li.separate img').height($('#menu-main li.bighover ul').height()-20);
		
	
	$('#menu-main li.hover ul li.top').width($('#menu-main li.hover ul').width()-21);
	$('#menu-main li.hover ul li.bottom').width($('#menu-main li.hover ul').width()-21);
	$('#menu-main li.hover ul li.bottom').css('top',$('#menu-main li.hover ul').height());
	$('#menu-main li.hover ul li.left, #menu-main li.hover ul li.right').height($('#menu-main li.hover ul').height()+10);
	$('#menu-main li.hover ul li.right').css('margin-left', $('#menu-main li.hover ul').width()-1);
	$('#menu-main li.hover ul li.separate img').height($('#menu-main li.hover ul').height()-10);*/
	
	
	
	//IE7 HACK
	
	if($.browser.msie === true && $.browser.version == '7.0')
	{
		$('#menu-main li.dd ul li.top').css('right', 0);
		$('#menu-main li.dd ul li.bottom').css('right', 0);
		$('#menu-main li.dd ul li.right').css('left', 0);
		$('.bottom-left').css('margin-top', -20);
		$('.bighover .top-right, .bighover .bottom-right').css('float', 'none').css('margin-left', $('#menu-main li.bighover ul').width() - 12);
		$('.hover .top-right, .hover .bottom-right').css('float', 'none').css('margin-left', $('#menu-main li.hover ul').width() - 12);
		$('.bottom-right').css('margin-top', -22)
	}
	
		
	$('#menu-main li.bighover,#menu-main li.hover').hover(function(){
		$(this).addClass("activat");
		$('ul' ,this).fadeIn(100);
	},function(){
		$(this).removeClass("activat");
		$('ul' ,this).fadeOut(100);
	});

	
	$('#menu-main li.dd ul li:not(.active) p').hide();
	
	/*$('#menu-main li>a').hover(function(){
		$(this).addClass('over');
	},function(){
		$(this).removeClass('over');
		$('label', this).remove();
	});*/
	
	
	/* INPUT RESET */
	$('input:text').each(function(){
		tempform='';
		$(this).focus(function(){if($(this).val()==$(this).attr('title')){tempform = $(this).val();$(this).val('');}});
		$(this).blur(function(){if($(this).val()==''){$(this).val(tempform);}});
	});
	
	$('input:text:not(.field)').each(function(){
		$(this).focus(function(){ 
			w=$(this).width();
			h=$(this).height();
			$(this).css({'border':'2px solid #cccccc','background':'#f9f9f9','width':(w-2)+'px','height':(h-2)+'px'});
		});
		$(this).blur(function(){
			w=$(this).width();
			h=$(this).height();
			$(this).css({'border':'1px solid #999999','background':'#ffffff','width':(w+2)+'px','height':(h+2)+'px'});
		});
	});
	
	$('textarea:not(.join)').each(function(){		
		$(this).focus(function(){ 
			w=$(this).width();
			h=$(this).height();
			$(this).css({'border':'2px solid #cccccc','background':'#f9f9f9','width':(w-2)+'px','height':(h-2)+'px'});
		});
		$(this).blur(function(){
			w=$(this).width();
			h=$(this).height();
			$(this).css({'border':'1px solid #999999','background':'#ffffff','width':(w+2)+'px','height':(h+2)+'px'});
		});
	});
	
	$("a").filter(function() {
    	//alert(this.hostname.substr(this.hostname.length-6,this.hostname.length));
        return this.hostname && this.hostname.substr(this.hostname.length-6,this.hostname.length) !== location.hostname.substr(location.hostname.length-6,location.hostname.length);
    }).attr('target', '_blank');
    
	
	
	/* HOMEPAGE */
	if ($("#topslider").length) $('#topslider').after('<div class="navWrapper"><a href="#" id="prev2"><img src="/images/back.gif" alt="Prev" /></a> <a href="#" id="next2"><img src="/images/fw.gif" alt="Next" /></a><div id="nav" class="nav"></div>').cycle({ 
		fx:     'fade', 
		speed:  'fast', 
		timeout: 5000, 
		next:   '#next2', 
		prev:   '#prev2',
		pager:  '#nav'
	});
	
	if ($('#home').width()>0) {
		
	};
	
	$('.box .res').hide();
	
	$('#control a').eq(0).click(function(){
		$(this).css("cursor","default");
		$('#control a').eq(1).css("cursor","pointer");
		$('.box .res').slideUp(200);
		$('.box .sec').slideDown(200);
		$('#control').css('background-position','0px 0px');
		$('#control a').eq(1).removeClass('active');
		$(this).addClass('active');
		return false;
		
	});
	
	$('#control a').eq(1).click(function(){
		$(this).css("cursor","default");
		$('#control a').eq(0).css("cursor","pointer");
		$('.box .res').slideDown(200);
		$('.box .sec').slideUp(200);
		$('#control').css('background-position','0px -36px');
		$('#control a').eq(0).removeClass('active');
		$(this).addClass('active');
		return false;
	});
	
	
	/* HOME-BLOGS */
	index=0;
	$('#home .tabs .wrap').css({'width':$('#home .tabs .wrap ul').size()*462});
	$('#home .tabs .control a:not(.active)').live('click',function(){		
		$('#home .tabs .control a.active').removeClass('active');
		$(this).addClass('active');
		index=$('#home .tabs .control a.active').index();
		$('#home .tabs .wrap').animate({marginLeft:'-'+index*462+'px'},500);
		return false;
	});
	$('#home .tabs .control a.active').live('click',function(){return false;});
	
	
	/* INNOVATION TABS */
	$('#innovation .tabs a').click(function(){
		o=$(this).index();
		$('#innovation .tabs a.active').removeClass('active');
		$(this).addClass('active');
		$('#innovation .tab.active').removeClass('active');
		$('#innovation .tab').eq(o).addClass('active');
	});
	
	/* INNOVATION FILTERS */
	$('#pfilter li').each(function(){
		p=$(this).parent();
		if ($(this).index()>6 && $(this).index()<$('li',p).size() && $(this).attr("class")!="more")
			$(this).hide();
		
	});
	$('#pfilter .more a').toggle(function(){
		p=$(this).parent().parent();
		$('li',p).each(function(){
			if ($(this).index()>6 && $(this).index()<$('li',p).size())
			$(this).slideDown();
		});
		return false;
		},function(){
		p=$(this).parent().parent();
		$('li',p).each(function(){
			if ($(this).index()>6 && $(this).index()<$('li',p).size())
			$(this).slideUp();
		});
		return false;
	});
	$('#pfilter li.first input').change(function(){
		if ($(this).is(':checked')){
			p=$(this).parent().parent();
			$('li:not(.first) input',p).each(function(){$(this).attr('checked',false)});
			buildFiltersList($("#cat_id").val(),pagenoi,pagenop,"","");
		} else {
			p=$(this).parent();
			$(this).attr('checked',true);	
			$('li:not(.first) input',p).each(function(){$(this).attr('checked',false)});
			buildFiltersList($("#cat_id").val(),pagenoi,pagenop,"","");
		}
	});
	$('#pfilter li:not(.first) input').change(function(){
		p=$(this).parent().parent().parent();
		if ($(this).is(':checked')){
			if($(this).parent().parent().attr('class')=="boolean")	
			{
				$('li input',p).attr('checked',false);
				$(this).attr("checked",true);
			}
			$('li.first input',p).attr('checked',false);
			buildFiltersList($("#cat_id").val(),pagenoi,pagenop,"","");
		}
		else
		{
			if ($(".filtercheck:checked",p).size()==0) $('li.first input',p).click();
			else buildFiltersList($("#cat_id").val(),pagenoi,pagenop,"","");
		}
		
	});
	$('#pfilter ul').each(function(){
		p=$(this).parent();
		if ($(this).index()>4)
		$(this).hide();
	});
	$('#pfadv').toggle(function(){
		p=$('#pfilter');
		$('ul',p).each(function(){
			if ($(this).index()>4)
			$(this).slideDown();
		});
		$(this).css('background',$('a#pfadv').css('background-image').replace('off','on'));
		return false;
		},function(){
		p=$('#pfilter');
		$('ul',p).each(function(){
			if ($(this).index()>4)
			$(this).slideUp();
		});
		$(this).css('background',$('a#pfadv').css('background-image').replace('on','off'));
		return false;
	});
	$('#pfcl').click(function(){
		$('#pfilter ul li:not(.first) input:checkbox').attr('checked',false);
		$('#pfilter ul li.first input:checkbox').each(function(){
			if ($(this).attr('checked')==false){
				$(this).click();
				$(this).attr('checked',true);
			}
		});
		
		return false;
	});
	
	
	/* PRODUCT */
	$('#product .tabs a').click(function(){
		o=$(this).index();
		$('#product .tabs a.active').removeClass('active');
		$(this).addClass('active');
		$('#product .tab.active').removeClass('active');
		$('#product .tab').eq(o).addClass('active');
		return false;
	});
	
	/* ARTICLE */
	$('.attachments a').attr("target","_new");
	
	/* REGISTER */
	$('#memberbox').slideUp();
	$('#memb,#memb1,#memb2,#memb3').toggle(function(){
		$('#memberbox').slideDown();
		 window.scroll(0,0);
	},function(){
		$('#memberbox').slideUp();
	});
	$('#memberbox #cancel').click(function(){$('#memberbox').slideUp();});
	
	/*if ($('#sidebar').height()>$('#content').height()) 
	{
		$("#bannerv").css("display","none");
		$('#content').css('height',$('#sidebar').height()-51);
	}*/
		
	$('#footer .column').last().addClass('last');
	mh = 0;
	$('#footer .column').each(function(){
		if ($(this).height()>mh) mh=$(this).height();
	});
	$('#footer .column').height(mh);
	
	/* connections */
	$("a.join").click(function(){
		$(this).slideUp();
		$('.connections #form_'+$(this).attr("title")).slideDown();		
	});
	$("a.cancel").click(function(){
		$("a.join[title="+$(this).attr("title")+"]").slideDown();
		$('.connections #form_'+$(this).attr("title")).slideUp();		
	});
	
	/* AREAS */
	$('#content .mainc').last().addClass('last');
	//if ($('#content .mainc').size()%2 == 0) $('#content .mainc').index($('#content .mainc').size()-1).addClass('last');
	if ($('#content .mainc').size()%2 == 0) $('#content .mainc:eq('+($('#content .mainc').size()-2)+')').addClass('last');
	
	
	var cache = [];
    $.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);
	    }
    }
    
    $.preLoadImages("/images/menu-b1-off.png","/images/menu-b1-on.png","/images/menu-b2-off.png","/images/menu-b2-on.png","/images/training-off.png","/images/training-on.png","/images/products-off.png","/images/products-on.png","/images/socialmedia.png","/images/menu-area-top.png","/images/menu-area-middle.png","/images/menu-area-bottom.png");
	
});

	$(".vendor").live("click", function(x){
		__click_on_Vendor($(this));
	});

})(jQuery);;

$(
	function()
	{
		// set up rollover
		$("img.ro").hover(
			function()
			{
				this.src = this.src.replace("-off","-on");
			},
			function()
			{
				this.src = this.src.replace("-on","-off");
			}
		);
	}
)

