
/* ++++++++++++++++++++++++++++++++
	++	yourzine.js							++
	++	extracted from					++
	++	jquery.pallette-0.1.8.js			++
	++										++
	++	Dependencies:					++
	++	- jQuery 1.2.6 or higher	++
	++++++++++++++++++++++++++++++++ */
	
	
(function( $ ) {
	$.fn.extend( {
	/* ========================
		==  Extending jQuery  ==
		======================== */
	
		palette: "0.1.8",
		yourzine: "0.1",
		
		/*contentObj: window.contentObj || {},
	
		hashRef: function() { // v0.1.5
			//	Finds corresponding element(s), based on href= attribute (hash) of first matched element. Works both ways.
			return this.is("[href*='#']") ? ( $(this[0].href.substring( this[0].href.lastIndexOf("#") )) ) : $("[href$='#" + this[0].id + "']");
		},
	
		forRef: function() { // v0.1.5
			//	Finds corresponding label(s), input, select or textarea, based on for= attribute of first matched element. Works both ways.
			return this.is("label[for]") ? $("#" + this[0].htmlFor) : $("label[for='" + this[0].id + "']");
		},
		
		overLabel: function() { // v0.1.6
			//	Makes 'overLabel' behavior possible. Works both on labels and form fields.
			//	Concept based on http://www.alistapart.com/articles/makingcompactformsmoreaccessible/
			//	CSS:		.jsOverLabel (on label)
			//				.jsOverLabelBlur (on parent of form field: blur)
			//	Deps.:	forRef() method (v0.1+)
			return this
				.each( function() {
					var jThis = $(this);
					var jRef = jThis.forRef();
					if ( jThis.is("label[for]") ) {
						var jFormControl = jRef;
						var jLabels = jThis;
					} else {
						var jFormControl = jThis;
						var jLabels = jRef;
					}
					if ( !( jFormControl.length > 0 && jLabels.length > 0 ) ) return true;	// continue
					
					jLabels.each( function() {
						$(this).addClass("jsOverLabel");
						if ( jFormControl.val() === "" ) jFormControl.parent().addClass("jsOverLabelBlur");
						jFormControl
							.focus( function() { $(this).parent().removeClass("jsOverLabelBlur"); } )
							.blur( function() { 
								var jFormControl = $(this);
								if ( jFormControl.val() === "" ) jFormControl.parent().addClass("jsOverLabelBlur");
							} )
							.click( function() { $(this).forRef().trigger("focus"); } );
					} );
				} );
		},*/
		
		clickable: function( cpTtl ) { // v0.1.8
			//	Makes elements clickable, linking to location specified by href= attribute of first descending link (where href is not "#" and does not start with "javascript:").
			// Args.:	cpTtl:	[Boolean | optional]	Specifies whether or not to copy the title= attribute from the link to clickable element (default: true)
			//	CSS:		.jsClickable (on this)
			//				.jsClickableHover (on this:hover)
			//				.jsGuide (on guiding link)
			return this
				.each( function() {
					var jClickElem = $(this);
					var jGuideLink = $("a[href]:not([href='#']):not([href^='javascript:'])", jClickElem).eq(0);
					var href = jGuideLink.attr("href");
					if ( !href ) return true;	// continue
					
					$(this).data("href", href);
					if ( ( cpTtl || cpTtl == null ) && !this.title && jGuideLink[0].title ) this.title = jGuideLink[0].title;
					jClickElem
						.click( function() { window.location.href = $(this).data("href"); } )
						.hover(
							function() { $(this).addClass("jsClickableHover"); },
							function() { $(this).removeClass("jsClickableHover"); }
						)
						.addClass("jsClickable");
					jGuideLink.addClass("jsGuide");
				} );
		}/*,
		
		selectNav: function() { // v0.1.7
			//	Adds auto submit behavior to select boxes, for navigational use. Works with keyboard too (in IE, FX and Op)
			//	CSS:		.jsSelectNav (on parent of select box)
			return this
				.filter("select")
				.each( function() {
					$(this)
						.focus( function() { $(this).data("origValue", this.value); } )
						.change( function() {
							if ( $(this).data("newValue") ) $(this).data("origValue", $(this).data("newValue"));
							$(this).data("newValue", this.value);
						} )
						.blur( navigate )
						.click( navigate )
						.parent().addClass("jsSelectNav");
					
					function navigate() {
						var newValue = $(this).data("newValue");
						if ( newValue && newValue != $(this).data("origValue") ) this.form.submit();
					};
				} );
		},
		
		popLink: function( props ) { // v0.1.8
			// Opens matching links in popup. Default properties can be overridden with props argument
			// Args.:	props:	[Object]		Key/value pairs of properties that differ from default
			//	CSS:		.jsPopup (on link, default class name can be overridden)
			
			// Default properties may be changed and can be overridden on function call:
			var defProps = {
				target: "_blank",			// [String]		Target name of popup
				blank: false,				// [Boolean]	Blank window: true > no properties are applied / false > properties are applied 
				width: 500,					// [Integer]	Width popup window
				height: 550,				// [Integer]	Height popup window
				absH: false,				// [Boolean]	Horizontal positioning: true > absolute / false > center
				absV: false,				// [Boolean]	Vertical positioning: true > absolute / false > center
				popH: 640,					// [Integer]	Horizontal position. If absHor is false, this value will be used as minimal screen width in case the available screen width is unknown
				popV: 480,					// [Integer]	vertical position. If absVert is false, this value will be used as minimal screen height in case the available screen height is unknown
				print: false,				// [Boolean]	Print version. If true, the toolbar will be shown in case the browser does not support window.print
				props: ["resizable"],	// [Array]		Array with, comma seperated, window propertie names [String] which must be 'on'. E.g. ['location','scrollbars']
				keepRef: false,			// [Boolean]	Keep reference to popup window. If true a reference will be kept in $.data("ref") stored on the link
				className: "jsPopup",	// [String]		Class name set on popup link
				replaceLoc: false			// [Boolean]	Replace popup location in browser's history or not
			};
			
			// Do not change code below:
			if ( !props ) props = {};
			for ( var p in defProps ) if ( !props[p] ) props[p] = defProps[p];
			
			var propString = "";
			if ( !props.blank ) {
				if ( props.print && !window.print && $.inArray("toolbar", props.props) == -1 ) props.props.push("toolbar");
				
				function calcPos( prop, dim ) {
					if (window.screen && window.screen.availWidth) prop = window.screen["avail" + dim];
					return Math.round((prop - props[dim.toLowerCase()]) / 2);
				};
				if ( !props.absH ) props.popH = calcPos( props.popH, "Width" );
				if ( !props.absV ) props.popV = calcPos( props.popV, "Height" );
				
				propString = "width=" + props.width + ",height=" + props.height + ",left=" + props.popH + ",top=" + props.popV;
				if ( props.props.length > 0 ) propString = propString + "," + props.props.join(",");
			};
			
			return this
				.filter("a[href], area[href]")
				.each( function() {
					$(this)
						.data("popup", {
							target:	props.target,
							props:	propString,
							repl:		props.replaceLoc,
							keepRef:	props.keepRef
						} )
						.click( function(e) {
							var popProps = $(this).data("popup");
							var popup = window.open(this.href, popProps.target, popProps.props, popProps.repl);
							if ( popProps.keepRef ) $(this).data("ref", popup);
							e.preventDefault();;
						} )
						.addClass(props.className);
				} );
		}*/
		
	} );
	
	$.extend( {
	/* ========================
		==  Custom functions  ==
		======================== */

		initMainMenu: function() {
			var selected = $("#mainMenu ul.nav > li.selected").eq(0);
			$("#mainMenu").data("selected", selected);
			
			$("#mainMenu ul.nav > li:not(.selected)")
				.hover(
					// mouseover:
					function(e) {
						$(this)
							.addClass("jsHover")
							.addClass("selected");
						$("#mainMenu")
							.data("selected")
							.removeClass("selected");
					},
					// mouseout:
					function(e) {
						$(this)
							.removeClass("jsHover")
							.removeClass("selected");
						$("#mainMenu")
							.data("selected")
							.addClass("selected");
					}
				);
		}
		
				
	} );
} )(jQuery);

/* ======================
	==  Function calls  ==
	====================== */

jQuery( function( $ ) {
	
	$.initMainMenu();
	$("#mainCategories .case, #casesOverview li:not(.categories li), #expertises .expertise").clickable();
	$(".news-items li").clickable();
	//$("#men li:not(.categories li)").clickable();
	//$("#management li:not(.categories li)").clickable();
} );