



function attachEditIcons(){

	// edit content icons
	// -------------------------------------------------
	// 
			
	$(".editcontenticons").replaceWith('<a id="editcontent" class="editcontent editicon"></a>'+
					'<div class="additional_editicons">'+
					'<a class="duplicateicon"></a>'+
					'<a class="deleteicon"></a>'+
					'<a class="settingsicon"></a>'+
					'<a class="moveicon"></a>'+										
					'</div>');
	// show & hide tooltip icons:				
	$(".editcontent").tooltip({
		effect: 'fade',
		// custom positioning
		position: 'bottom center',
		// move tooltip a little bit to the right
		offset: [0, 0],
		// there is no delay when the mouse is moved away from the trigger
		delay: '0'
	});
	
};




function dropDownMenu(){

	// edit content icons
	// -------------------------------------------------
	// 
	
		$("ul.subnav").parent().addClass('subMenuItems');// add class
		$("ul.subnav").parent().prepend('<span class="subnavTrue"></span>');

		$("ul.subnav").css('top', function(){// get .topnav li height and move submenu down
	 		return $("ul.topnav li").height();
	 		});

		
		$("ul.topnav .subMenuItems").hover(function() { //is hovered over...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).find("ul.subnav").slideDown('normal').show(); //Drop down the subnav on hover

		$(this).hover(function() {
		}, function(){	
			$(this).find("ul.subnav").fadeOut('fast'); //When the mouse hovers out of the subnav, move it back up
		});
	});
};





function linksWithIcons(){

	// give file spesific classes to linnks 
	// -------------------------------------------------
	// 

	$("a[@href$=pdf]").addClass("pdf");

	$("a[@href$=zip]").addClass("zip");

	$("a[@href$=psd]").addClass("psd");

	$("a:not([@href*=http://www.meizo.com])").not("[href^=#]")
	  .addClass("external")
	  .attr({ target: "_blank" });

};








$.tools.tabs.addEffect("fap", function(i, done) {

	// add fade effect for tabs 
	// -------------------------------------------------
	// 

	this.getPanes().fadeOut();

	this.getPanes().eq(i).fadeIn(function()  {
		

		// the supplied callback must be called after the effect has finished its job
		done.call();
	});
});

function tabs(){
/* 	$("div.css-tabs").tabs(".panes > div", {effect: 'fap'}); */
	$("div.css-tabs").tabs(".panes > div");
	
	/*
var innerdiv = $(".panes div");
	var parentdiv = $(innerdiv).parent().parent().find(".css-tabs");
	var parentwidth = $(parentdiv).width();
	var borderWidth =($(innerdiv).outerWidth() - $(innerdiv).width());
	var inheritwidth = parentwidth-borderWidth;
	$('.panes div').css( 'width', inheritwidth );
*/



}



function subtractPaddingFromWidth(){
	var subtractTarget = $(".JSsubtractPadding");
	var originalWidth = $(subtractTarget).width();
	var padding =($(subtractTarget).outerWidth() - $(subtractTarget).width());
	var newWidth = originalWidth-padding;
	$(this).css( 'width', newWidth );	
	alert(newWidth);
}




function inheritWidth(){

	// subtract padding and margin from the width of parent object and set it as width 
	// -------------------------------------------------
	// 

	var innerdiv = $(".inheritwidth");
	var parentdiv = $(innerdiv).parent().width();
	var borderWidth =($(innerdiv).outerWidth() - $(innerdiv).width());
	var inheritwidth = parentdiv-borderWidth;
	alert(inheritwidth);
	$(this).css( 'width', inheritwidth );
}


function overlayBox() {

	// overlaybox 
	// -------------------------------------------------
	// 

	$("a[rel].OverlayTrigger").overlay({
	effect: 'apple',
	top: 20,
	mask: {

		// you might also consider a "transparent" color for the mask
		color: '#eee',

		// load mask a little faster
		loadSpeed: 200,

		// very transparent
		opacity: 0.85
	},

	// disable this for modal dialog-type of overlays
	// closeOnClick: false,
	
	
	
	});
	//opens overlay from links where class=OverlayTrigger, rel atribute points to overlay right div
}

function scrollableOverlay(){
	$(".scrollableOverlay").scrollable({ 
	vertical: true, 
	mousewheel: false,
	circular: false 
	});
}




$(document).ready(function() {

	// trigger editicons
	attachEditIcons();

	// trigger dropdownmenu
	dropDownMenu();

	// trigger tabs
	tabs();

	// subtract padding from button widths
	//subtractPaddingFromWidth()

	// trigger overlay boxes for #OverlayTrigger
	overlayBox();
	
	// trigger scrollableOverlay
	scrollableOverlay();
});
