// JavaScript Document
// Masonry for Navigation
;(function($){$.fn.masonry=function(options,callback){function placeBrick($brick,setCount,setY,setSpan,props){var shortCol=0;for(i=0;i<setCount;i++){if(setY[i]<setY[shortCol])shortCol=i}$brick.css({top:setY[shortCol],left:props.colW*shortCol+props.posLeft});for(i=0;i<setSpan;i++){props.colY[shortCol+i]=setY[shortCol]+$brick.outerHeight(true)}}function masonrySetup($wall,opts,props){props.$bricks=opts.itemSelector==undefined?opts.$brickParent.children():opts.$brickParent.find(opts.itemSelector);if(opts.columnWidth==undefined){props.colW=props.masoned?$wall.data('masonry').colW:props.$bricks.outerWidth(true)}else{props.colW=opts.columnWidth}props.colCount=Math.floor($wall.width()/props.colW);props.colCount=Math.max(props.colCount,1)}function masonryArrange($wall,opts,props){if(!props.masoned)$wall.css('position','relative');if(!props.masoned||opts.appendedContent!=undefined){props.$bricks.css('position','absolute')}var cursor=$('<div />');$wall.prepend(cursor);props.posTop=Math.round(cursor.position().top);props.posLeft=Math.round(cursor.position().left);cursor.remove();if(props.masoned&&opts.appendedContent!=undefined){props.colY=$wall.data('masonry').colY;for(i=$wall.data('masonry').colCount;i<props.colCount;i++){props.colY[i]=props.posTop}}else{props.colY=[];for(i=0;i<props.colCount;i++){props.colY[i]=props.posTop}}if(opts.singleMode){props.$bricks.each(function(){var $brick=$(this);placeBrick($brick,props.colCount,props.colY,1,props)})}else{props.$bricks.each(function(){var $brick=$(this);var colSpan=Math.ceil($brick.outerWidth(true)/props.colW);colSpan=Math.min(colSpan,props.colCount);if(colSpan==1){placeBrick($brick,props.colCount,props.colY,1,props)}else{var groupCount=props.colCount+1-colSpan;var groupY=[0];for(i=0;i<groupCount;i++){groupY[i]=0;for(j=0;j<colSpan;j++){groupY[i]=Math.max(groupY[i],props.colY[i+j])}}placeBrick($brick,groupCount,groupY,colSpan,props)}})}props.wallH=0;for(i=0;i<props.colCount;i++){props.wallH=Math.max(props.wallH,props.colY[i])}$wall.height(props.wallH-props.posTop);callback.call(props.$bricks);$wall.data('masonry',props)}function masonryResize($wall,opts,props){var prevColCount=$wall.data('masonry').colCount;masonrySetup($wall,opts,props);if(props.colCount!=prevColCount)masonryArrange($wall,opts,props)}return this.each(function(){var $wall=$(this);var props=$.extend({},$.masonry);props.masoned=$wall.data('masonry')!=undefined;var previousOptions=props.masoned?$wall.data('masonry').options:{};var opts=$.extend({},props.defaults,previousOptions,options);props.options=opts.saveOptions?opts:previousOptions;callback=callback||function(){};if(props.masoned&&opts.appendedContent!=undefined){opts.$brickParent=opts.appendedContent}else{opts.$brickParent=$wall}if(opts.$brickParent.children().length>0){masonrySetup($wall,opts,props);masonryArrange($wall,opts,props);var resizeOn=previousOptions.resizeable;if(!resizeOn&&opts.resizeable){$(window).bind('resize.masonry',function(){masonryResize($wall,opts,props)})}if(resizeOn&&!opts.resizeable)$(window).unbind('resize.masonry')}else{return this}})};$.masonry={defaults:{singleMode:false,columnWidth:undefined,itemSelector:undefined,appendedContent:undefined,saveOptions:true,resizeable:true},colW:undefined,colCount:undefined,colY:undefined,wallH:undefined,masoned:undefined,posTop:0,posLeft:0,options:undefined,$bricks:undefined,$brickParent:undefined}})(jQuery);

// Simple Tooltip
(function($){ $.fn.simpletooltip = function(){
	return this.each(function() {
		var text = $(this).attr("title");
		$(this).attr("title", "");
		if(text != undefined) {
			$(this).hover(function(e){
				var tipX = e.pageX + 12;
				var tipY = e.pageY + 12;
				$(this).attr("title", ""); 
				$("body").append("<div id='simpleTooltip' style='position: absolute; z-index: 100; display: none;'>" + text + "</div>");
				if($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
				else var tipWidth = $("#simpleTooltip").width()
				$("#simpleTooltip").width(tipWidth);
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("fast");
			}, function(){
				$("#simpleTooltip").remove();
				$(this).attr("title", text);
			});
			$(this).mousemove(function(e){
				var tipX = e.pageX + 12;
				var tipY = e.pageY + 12;
				var tipWidth = $("#simpleTooltip").outerWidth(true);
				var tipHeight = $("#simpleTooltip").outerHeight(true);
				if(tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
				if($(window).height()+$(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("fast");
			});
		}
	});
}})(jQuery);
/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:350};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

$(document).ready(function(){
						   
	//drop down
	$('#category-nav').hoverIntent(
		 function () {
		    $('#category-mdd').fadeIn(100);
			$('#category-nav a').css('background-position','-114px -282px');
			$('#category-nav a').css('height','65px');
		 },
		 function () {
			    $('#category-mdd').fadeOut(100);
				$('#category-nav a').css('background-position','-1px -282px');
				$('#category-nav a').css('height','45px');
		 }
	);
	$('#material-nav').hoverIntent(
		 function () {
		    $('#material-mdd').fadeIn(100);
			$('#material-nav a').css('background-position','-114px -351px');
			$('#material-nav a').css('height','65px');
		 },
		 function () {
			    $('#material-mdd').fadeOut(100);
				$('#material-nav a').css('background-position','-1px -351px');
				$('#material-nav a').css('height','45px');
		 }
	);
	$('#feature-nav').hoverIntent(
		 function () {
		    $('#feature-mdd').fadeIn(100);
			$('#feature-nav a').css('background-position','-114px -417px');
			$('#feature-nav a').css('height','65px');
		 },
		 function () {
			    $('#feature-mdd').fadeOut(100);
				$('#feature-nav a').css('background-position','-1px -417px');
				$('#feature-nav a').css('height','45px');
		 }
	);
	// MDD Masonry
	$('#primary').masonry({
		columnWidth: 110, 
		itemSelector: '#header ul li div.mdd ul li' 
	});
	// Favorites list
	$('.view-fav').hoverIntent(
		 function () {
			$('.mfp_favorites').fadeIn(100);
			$('.view-fav a:first').css({
							'background-color' : '#85D4F4',
     						'padding' : '2px 6px 20px',
     						'color' : '#fff'
								 });
		 },
		 function () {
			$('.mfp_favorites').fadeOut(100);
			$('.view-fav a:first').css({
							'background-color' : '#fff',
     						'padding' : '0',
     						'color' : '#85D4F4'
								 });
		 }
	);
	//thumbnail hover
	$('.post-info').css('display', 'none');					   
	$('.post').hover(
		 function () {
		    $(this).children('.post-info').fadeIn(100);
			$(this).children('.thumb').css({'opacity' : '.2'});
		 },
		 function () {
		    $(this).children('.post-info').fadeOut(100);
			$(this).children('.thumb').css({'opacity' : '1'});
		 }
	);
	$('.logged-in').click(function(){
		$('.logged-in').toggleClass("liked")
	});
	$('#comments-int').css('display','none');
	$('#comments h2').addClass('expandable').attr("title", "Click to show/hide Comments section");

	$('#comments h2').toggle(function() {
  		$('#comments-int').slideDown();
		$(this).toggleClass('expanded');
	}, function() {
 		$('#comments-int').slideUp();
		$(this).toggleClass('expanded');
	});
	$('.next-post, .prev-post, #fav-login, .expandable ').simpletooltip();
	//$(".cat-list a[rel^='category']").parent().append("</li><li><ul>");
	$('#regbox').click(function(){
		$('#regbox:visible').fadeOut();							
	});
	// Share button script
	$('ul#share-networks').css('display', 'none');
	$('li.share').hover(
			function(){
				$('ul#share-networks').stop(true, true).slideDown();
			},
			function(){
				$('ul#share-networks').slideUp();
			}
	);	
	$('li.share').addClass('link');
	//remove margin from every other div in "New Products" widget
	$('.new-products div.post:nth-child(2n)').css({
												  'margin-right' : '0'
												  });
});
