/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($){
	$.extend($.fx.step, {
		backgroundPosition : function(fx){
			if(fx.state === 0 && typeof fx.end == 'string'){
				var start = $.curCSS(fx.elem,'backgroundPosition');
				start     = toArray(start);
				fx.start  = [start[0],start[2]];
				var end   = toArray(fx.end);
				fx.end    = [end[0],end[2]];
				fx.unit   = [end[1],end[3]];
			}
			var nowPosX = [];
			nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
			nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
			fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
			function toArray(strg){
				strg    = strg.replace(/left|top/g, '0px');
				strg    = strg.replace(/right|bottom/g, '100%');
				strg    = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
				var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
				return [parseFloat(res[1], 10), res[2], parseFloat(res[3] , 10), res[4]];
			}
		}
	});
})(jQuery);



$(document).ready(function(){
	// open gmap instructions box on click
	$("#openMapInstructions").click(function(){ 
		$("#mapInstructions").slideToggle("fast");
		$(this).slideToggle("fast");
		CookieCreate('hide_map_instructions', '0', 0);
	});
	// close gmap instructions box on click
	$("#mapInstructions").click(function(){ 
		$(this).slideToggle("fast");
		$("#openMapInstructions").slideToggle("fast");
		CookieCreate('hide_map_instructions', '1', 0);
	});
	// set default state to closed
	$("#gm_markers").hide();
	// open/close map results in box
	$('#results_list_toggle, #gm_markers').click(function () { 
		$("#gm_markers").slideToggle("fast"); 
	});
	// on page load
	var test = CookieGet('hide_map_instructions');
	if(test && test == 1){
		$("#mapInstructions").slideToggle("fast");
		$("#openMapInstructions").slideToggle("fast");
	}
/*
	// contest form links
	$(".iframe").fancybox({
		'hideOnContentClick' : false,
		'width'              : 400,
		'height'             : 500,
		'padding'            : 0,
		'margin'             : 0,
		'overlayShow'        : true,
		'overlayOpacity'     : 0.8,
		'overlayColor'       : '#000',
		'centerOnScroll'     : true
	});
	// listing detail images
	$(".thickbox").fancybox({
		'padding'            : 0,
		'margin'             : 0,
		'overlayShow'        : true,
		'overlayOpacity'     : 0.8,
		'overlayColor'       : '#000',
		'centerOnScroll'     : true
	});
*/
	$('#slider').bxSlider({
		mode: 'horizontal',                 // 'horizontal', 'vertical', 'fade'
		infiniteLoop: true,                 // true, false - display first slide after last
		hideControlOnEnd: false,            // true, false - if true, will hide 'next' control on last slide and 'prev' control on first
		controls: true,                     // true, false - previous and next controls
		speed: 500,                         // integer - in ms, duration of time slide transitions will occupy
		easing: 'swing',                    // used with jquery.easing.1.3.js - see http://gsgd.co.uk/sandbox/jquery/easing/ for available options
		pager: false,                        // true / false - display a pager
		pagerSelector: null,                // jQuery selector - element to contain the pager. ex: '#pager'
		pagerType: 'full',                  // 'full', 'short' - if 'full' pager displays 1,2,3... if 'short' pager displays 1 / 4
		pagerLocation: 'bottom',            // 'bottom', 'top' - location of pager
		pagerShortSeparator: '/',           // string - ex: 'of' pager would display 1 of 4
		pagerActiveClass: 'pager-active',   // string - classname attached to the active pager link
		nextText: 'next',                   // string - text displayed for 'next' control
		nextImage: '',                      // string - filepath of image used for 'next' control. ex: 'images/next.jpg'
		nextSelector: null,                 // jQuery selector - element to contain the next control. ex: '#next'
		prevText: 'prev',                   // string - text displayed for 'previous' control
		prevImage: '',                      // string - filepath of image used for 'previous' control. ex: 'images/prev.jpg'
		prevSelector: null,                 // jQuery selector - element to contain the previous control. ex: '#next'
		captions: false,                    // true, false - display image captions (reads the image 'title' tag)
		captionsSelector: null,             // jQuery selector - element to contain the captions. ex: '#captions'
		auto: true,                        // true, false - make slideshow change automatically
		autoDirection: 'next',              // 'next', 'prev' - direction in which auto show will traverse
		autoControls: false,                // true, false - show 'start' and 'stop' controls for auto show
		autoControlsSelector: null,         // jQuery selector - element to contain the auto controls. ex: '#auto-controls'
		autoStart: true,                    // true, false - if false show will wait for 'start' control to activate
		autoHover: false,                   // true, false - if true show will pause on mouseover
		autoDelay: 0,                       // integer - in ms, the amount of time before starting the auto show
		pause: 6000,                        // integer - in ms, the duration between each slide transition
		startText: 'start',                 // string - text displayed for 'start' control
		startImage: '',                     // string - filepath of image used for 'start' control. ex: 'images/start.jpg'
		stopText: 'stop',                   // string - text displayed for 'stop' control
		stopImage: '',                      // string - filepath of image used for 'stop' control. ex: 'images/stop.jpg'
		ticker: false,                      // true, false - continuous motion ticker mode (think news ticker)
		                                    // note: autoControls and autoControlsSelector apply to ticker!
		tickerSpeed: 5000,                  // integer - has an inverse effect on speed. therefore, a value of 10000 will 
		                                    // scroll very slowly while a value of 50 will scroll very quickly.
		tickerDirection: 'next',            // 'next', 'prev' - direction in which ticker show will traverse
		tickerHover: false,                 // true, false - if true ticker will pause on mouseover
		wrapperClass: 'bx-wrapper',         // string - classname attached to the slider wraper
		startingSlide: 0,                   // integer - show will start on specified slide. note: slides are zero based!
		displaySlideQty: 1,                 // integer - number of slides to display at once
		moveSlideQty: 1,                    // integer - number of slides to move at once
		randomStart: true                 // true, false - if true show will start on a random slide					  
	});
});


function CookieCreate(name, value, days){
	var expires = "";
	if(days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}


function CookieGet(name){
	var nameEQ = name + "=";
	var ca     = document.cookie.split(';');
	for(var i = 0; i < ca.length; i++){
		var c = ca[i];
		while(c.charAt(0) == ' '){
			c = c.substring(1, c.length);
		}
		if(c.indexOf(nameEQ) == 0){
			return c.substring(nameEQ.length, c.length);
		}
	}
	return null;
}


function CookieDelete(name){
	createCookie(name, "", -1);
}

function Details_GM_Init(lat, lng, title){
	if(lat && lng){
		$(document).ready(function(){
			var latlng    = new google.maps.LatLng(lat, lng);
			var myOptions = {
				zoom: 14,
				center: latlng,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};
			var map = new google.maps.Map(document.getElementById("details_gmap"), myOptions);
			// marker
			var marker = new google.maps.Marker({
				title    : title,
				position : latlng,
				map      : map
			});
		});
	}
}

function Details_Slideshow(id){
	if(id){
		$(".userSlideshow").userSlideshow({url: '/templates/jrussell/js/jquery.userSlideshow/album.php?id=' + id});
	}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
