var jspapi_hthm, olay_autohide, rolloversInit = new Function, updateGalLinks = new Function;

/* FW100R5 */
/* (c)2011 SugarHill Works LLC - http://www.sugarhillworks.com */
/**
 * A simple querystring parser.
 * Example usage: var q = $.parseQuery(); q.fooreturns  "bar" if query contains "?foo=bar"; multiple values are added to an array. 
 * Values are unescaped by default and plus signs replaced with spaces, or an alternate processing function can be passed in the params object .
 * http://actingthemaggot.com/jquery
 *
 * Copyright (c) 2008 Michael Manning (http://actingthemaggot.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 **/
$.parseQuery = function(qs,options) {
	var q = (typeof qs === 'string'?qs:window.location.search), o = {'f':function(v){return unescape(v).replace(/\+/g,' ');}}, options = (typeof qs === 'object' && typeof options === 'undefined')?qs:options, o = $.extend({}, o, options), params = {};
	$.each(q.match(/^\??(.*)$/)[1].split('&'),function(i,p){
		p = p.split('=');
		p[1] = o.f(p[1]);
		params[p[0]] = params[p[0]]?((params[p[0]] instanceof Array)?(params[p[0]].push(p[1]),params[p[0]]):[params[p[0]],p[1]]):p[1];
	});
	return params;
}
var q = $.parseQuery();



// HANDLE LINKS TO EXTERNAL PAGES
var windowObjectReference = null;
var PreviousUrl, ct=1;
function newWin(strUrl, windowOptions, forceNew)
{
	// catch relative links
	if (!strUrl.match('http://') || strUrl.match(rootPath)) {
		window.location = strUrl;
		return;
	}
	
	if (forceNew) {
		windowObjectReference = null;
		ct++
	}
	if (!windowOptions) { var windowOptions = "width=1000,height=640,scrollbars=yes,resizable=yes,toolbar=yes,location=yes,status=yes,titlebar=yes"; }
	if(windowObjectReference == null || windowObjectReference.closed || !windowObjectReference || !windowObjectReference.location) {
		windowObjectReference = window.open(strUrl, "SingleSecondaryWindowName"+(forceNew ? ct : ''), windowOptions);
		windowObjectReference.focus();
	} else if (PreviousUrl != strUrl) {
		windowObjectReference.focus();
		windowObjectReference = window.open(strUrl, "SingleSecondaryWindowName"+(forceNew ? ct : ''), windowOptions);
	} else {
		windowObjectReference.focus();
	};
	PreviousUrl = strUrl;
}



// -- BEG SITE SETTINGS ----------------------------------------------------------------------------------------
var autoforwardTo, autoforwardWait, default_scroll_settings={}, jspapi,
	months = ['January','February','March','April','May','June','July','August','September','October','November','December'],
	days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
	thisItemDate;

$(function($){
	$.fn.reverse = [].reverse;
	$.extend({
		vpwidth: function(){
			var viewportwidth;
			if (typeof window.innerWidth != 'undefined') {
				viewportwidth = window.innerWidth;
			} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
				viewportwidth = document.documentElement.clientWidth;
			} else {
				viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
			}
			return viewportwidth;
		}
	});
	$.extend({
		vpheight: function(){
			var viewportheight;
			if (typeof window.innerHeight != 'undefined') {
				viewportheight = window.innerHeight;
			} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientHeight != 'undefined' && document.documentElement.clientHeight != 0) {
				viewportheight = document.documentElement.clientHeight;
			} else {
				viewportheight = document.getElementsByTagName('body')[0].clientHeight;
			}
			return viewportheight;
		}
	});




	$.fn.toggleFade = function(settings) {
		settings = jQuery.extend(
			{
			speedIn: "normal",
			speedOut: settings.speedIn
			}, settings
		);
		return this.each(function()
		{
			var isHidden = jQuery(this).is(":hidden");
			jQuery(this)[ isHidden ? "fadeIn" : "fadeOut" ]( isHidden ? settings.speedIn : settings.speedOut);
		});
	};



	$.fn.hoverIntent = function(f,g) {
		var cfg = {
			sensitivity: 1,
			interval: 100,
			timeout: 1000
		};
		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);
	};

		   
		   




	// GALLERY HOLD PREVIEWS
	if (window.location.toString().match('_hold')) {
		$('<div></div>').css({position:'absolute',
							top:'0px',
							left:'0px',
							width: '100%',
							height: '20px',
							paddingTop: '5px',
							background: '#663366',
							color: '#ECC',
							textAlign: 'center',
							zIndex: '999999999'}).html('This is a preview and NOT live on the site.').appendTo($('#fullscr'));
	}
	
	// SHARING SETUP
	// facebook
	setTimeout(function(){
		$('#like_btn').load(function(){
			$('#like_btn_mask').css({display:'none'});
		}).attr('src',encodeURI('http://www.facebook.com/plugins/like.php?href=http://katrinreifeiss.com&layout=button_count&show_faces=false&width=50&action=like&font=arial&colorscheme=light&height=21&ref=katrinreifeiss'));
	},1250);
	//addthis
	var addthis_config =
	{
	   pubid: "ra-4e08c7951dbf7c09",
	   ui_header_color: "#FF3300",
	   ui_header_background: "#FFFFFF",
	   ui_cobrand: "Katrin Reifeiss", //'Designs by' is too long to fit
	   ui_offset_top: 0,
	   ui_offset_left: 16,
	   ui_use_addressbook: true, 
	   services_compact: 'facebook, twitter, digg, email, google, favorites, stumbleupon, linkedin, delicious, more',
	   ui_delay: 250	   
	}
	var addthis_share =
	{
	   url: (window.location).toString(),
	   title: "Designs by Katrin Reifeiss",
	   description: "Designs by Katrin Reifeiss"		   
	}
	setTimeout(function(){addthis.button('.sharing_button', addthis_config, addthis_share);},1250);

		
	// SETTINGS FOR SITE-WIDE NAV MENU(S)
	function initMenu (menu_cntr, over_col, out_col, bgover_col, bgout_col, cur_bg_css, cur_a_css) {
		var slinks = menu_cntr.find('li > a[href]'),
		url = (window.location.toString()).replace(/index\.php$/, ''),
		rel,
		href,
		homePage;
		function currentPage(lnk) {
			$(lnk).removeAttr('href');
			$(lnk).parent().addClass('current-page');
			// also current page the submenu header
			$(lnk).parent().parent().parent().addClass('current-page').addClass('current-page-hdr');
		}
		for (var i = 0; i < slinks.length; i++) {
			rel = $(slinks[i]).attr('rel');
			href = rootPath + $(slinks[i]).attr('href').replace(/(\.\.\/)+/,'');
			if ($(slinks[i]).attr('href')) {//alert($(slinks[i]).attr('href'));
				if (rel) {
					if (url.match(rel)) {
						currentPage(slinks[i]);
					}
				} else if ((url === rootPath) && (href === rootPath)) { // ROOT
					currentPage(slinks[i]);
				} else if (href.match(url) && (url !== rootPath)) {
					currentPage(slinks[i]);
				} else if (url.match(href) && href.match(/\/shop\//)) { // KR SHOP ONLINE HEADER LINK HIGHLIGHT
					$(slinks[i]).parent().removeClass('menuFade').unbind('mouseover').unbind('mouseout');
					$(slinks[i]).css({color:'#e82e23'}).unbind('mouseover').unbind('mouseout');
					$(slinks[i]).hover(
						function() { //over
							$(this).css({color:'#FF3300'});
						},
						function() { //out
							$(this).css({color:'#e82e23'});							
						}
					);
				}
			}
		}
		
		menu_cntr.find('.menuFade:not(.current-page):not(.disabled)').hover( 
			function() { 
				if ($(this).children('.menuitem_bg').length > 0) {
					$(this).children('.menuitem_bg').stop(true, true).fadeTo(750, 1);
				}
				$(this).children('a').eq(0).stop(true, true).animate({color:over_col}, 750);
			}, 
			function(){
				if ($(this).children('.menuitem_bg').length > 0) {
					$(this).children('.menuitem_bg').eq(0).stop(true, true).fadeTo(750, 0);
				}
					$(this).children('a').eq(0).stop(true, true).animate({color:out_col}, 750);
			}
		);
		menu_cntr.find('.current-page > a').css(cur_a_css);
		menu_cntr.find('.current-page-hdr > a').css({cursor:'pointer'});
	}
	// -------------------- init site menus --------------------
	if ($("#menu_cntr_cntr").length > 0) {
		$('#menu_cntr > ul').css({display:'block',visibility:'visible'});
		ddsmoothmenu.init({
			mainmenuid: "menu_cntr", //menu DIV id
			orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
			classname: 'ddsmoothmenu', //class added to menu's outer DIV
			//customtheme: ["#1c5a80", "#18374a"],
			contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
		});
		initMenu($('#menu_cntr'), '#FF3300', '#000', '#FFF', '#FFF', {background:'none', opacity:0, '-moz-opacity':0, 'filter':'alpha(opacity=0)'}, {cursor:'default', color:'#e82e23'});
	}




	// SETTINGS FOR GENERAL USE VERTICAL SCROLL PANES
	default_scroll_settings = {
		showArrows: true, // controls whether to display arrows for the user to scroll with (defaults to false)
		animateScroll: true, // whether to animate when calling scrollTo and scrollBy (defaults to false)
		animateDuration: 750, // [int] 300
		animateEase: 'linear', //[str] 'linear'
		verticalDragMinHeight: 50, // [int] - the minimum height to allow the drag bar to be (defaults to 0)
		maintainPosition: true //[boolean] - Whether the contents of the scroll pane maintains its position when you re-init it(so it doesn't scroll as you add more content) (default true)
	};
	if ($('.scroll-pane').length > 0) {
		$('#scrollPaneImgs').jScrollPane(default_scroll_settings);
		$('#gal_overlay_content').jScrollPane(default_scroll_settings);
		jspapi = $('#scrollPaneImgs').data('jsp');
		jspapi_stmt = $('#gal_overlay_content').data('jsp');
		var vScroll_TO;
		$('#hScroll_hotspotL').hoverIntent({
			over:function(){
				clearTimeout(img_scroll_TO);
				vScroll_TO = setInterval(function(){jspapi.scrollByX(-20, false);},30);
			},
			out:function(){
				clearInterval(vScroll_TO);
			},timeout:0});
		$('#hScroll_hotspotR').hoverIntent({over:function(){vScroll_TO = setInterval(function(){jspapi.scrollByX(20, false);},30);},out:function(){clearInterval(vScroll_TO);},timeout:0});

	}
	
	// SET UP ROLLOVER ANIMATIONS
	rolloversInit = function() {
		$(".fade_link").hover( 
			function() {
				$(this).stop(true).animate({color:"#FF3300"}, 500);			
			}, 
			function() {
				$(this).stop(true).animate({color:"#000"}, 500);
			}
		);
		$(".fade_link-hdr").hover( 
			function() {
				$(this).stop(true).animate({color:"#FF3300"}, 500);			
			}, 
			function() {
				$(this).stop(true).animate({color:"#000"}, 500);
			}
		);
		$(".fade_link-ftr").hover( 
			function() { 
				$(this).stop(true).animate({color:"#999"}, 500);
			}, 
			function(){
				$(this).stop(true).animate({color:"#666"}, 500)
			}
		);
	}
	rolloversInit();

	updateGalLinks = function() {
		if (($('#shop_txt').length > 0) || ($('#press').length > 0)) {
			$('#shop_txt > p > a, .caption1_txt > a, .caption2_txt > a').each(function(){
				if ($(this).hasClass('fade_link')) { return; }
				$(this).addClass('fade_link');
				if ($(this).attr('href').match(/^http\:\/\//)) {
					$(this).unbind('click');
					$(this).click(function(){ newWin($(this).attr('href')); return false; });
				}
			});
		}
	}



	// SET UP VERTICAL POSITIONING ON INFO PAGES
	// Call this function to vertically center a content container in its parent. Takes jq selectors as arguments.
	function vCenter(content_cntr, parent_cntr, topOff) {
		if (!topOff) { topOff = 0; }
		var topPos = $(parent_cntr+' > div:first').css({paddingTop:'0', marginTop:'0'}).offset().top;
		var btmPos = $(parent_cntr+' > div:last').css({paddingBottom:'0', marginBottom:'0'}).offset().top + $(parent_cntr+' > div:last').height();
		var content_h = btmPos - topPos;
		if (content_h < 1) {
			content_h = parseInt($(content_cntr).css('height'));
		}
		var newTopPos = Math.floor((($(parent_cntr).height() / 2) - (content_h / 2)));
		$(content_cntr).css({top:(newTopPos+topOff)+'px'}); // use top: or paddingTop: depending on content 'push' needs, css, etc.
	}
	if ($("#main_txt_scr_cntr").length > 0) {
			vCenter('#v_center_wrap', '#main_txt_scr_cntr')
	}
	
	
	// INIT SLIDESHOW
	if ($('#ss_cntr').length > 0) {
		ss_init();
	}
	if ($('#auto_ss_cntr').length > 0) {
		ss_init();
	}
	if ($('#index_thumbs').length > 0) {
		$('#index_thumbs > a > img').hover(
			function() { $(this).stop(true,true).fadeTo(500, 0.6); },
			function() { $(this).stop(true,true).fadeTo(500, 1); }
		);
	}
	
	
	if ($('#gal_overlay_cntr').length > 0) {
		$('#gal_overlay_x,#gal_overlay_bg,#overlay-txt-cntrs > div[id^=olay-txt-]').click(function(){$('#gal_overlay').prev().andSelf().fadeOut(olay_fade_duration);});
	}
});







// -- END SETTINGS ----------------------------------------------------------------------------------------









