/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.1, 11.09.2007
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Changelog:
 *    11.09.2007 Version 1.1
 *    - removed noConflict
 *    - added png-support for input type=image
 *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
 *    31.05.2007 initial Version 1.0
 * --------------------------------------------------------------------
 * @example $(function(){$(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready
 *
 * jQuery(function(){jQuery(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready when using noConflict
 *
 * @example $(function(){$('div.examples').pngFix();});
 * @desc Fixes all PNG's within div with class examples
 *
 * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
 * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
 * --------------------------------------------------------------------
 */

(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: 'blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[@src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});
		
		//fix input with png-source
		jQuery(this).find("input[@src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});
	
	}
	
	return jQuery;

};

})(jQuery);




$(function(){
	
	/*
	$('.hmenu a:path').each(function() {
		$(this).removeClass('rollover');
		normal = $(this).find("img").attr("src");
		name = normal.length;
		hover = normal.substr(0, name-4);
		hover = hover+'_o.gif';
		//$(this).find("img").attr({ src: hover});
		$(this).replaceWith('<img src="'+hover+'" />');
	});
	*/
	$(document).pngFix();
		
	$('#panel1').jScrollPane({showArrows:true, scrollbarWidth:8, wheelSpeed:10 });
	$('#panel2').jScrollPane({showArrows:true, scrollbarWidth:8, wheelSpeed:10 });
	$(".lightbox").lightbox({fileLoadingImage:'/js/images/loading.gif',fileBottomNavCloseImage:'/js/images/closelabel.gif'});
	
	$(".rollover").hover(
		function() {
			normal = $(this).find("img").attr("src");
			name = normal.length;
			hover = normal.substr(0, name-4);
			hover = hover+'_o.gif';
			$(this).find("img").attr({ src: hover});
		},
			function() {
			$(this).find("img").attr({ src: normal});
		}
	)

	$(".rollover").find("img").each(function(i) {
		temp = this.src;
		tmpname = temp.length;
		pre = temp.substr(0, tmpname-4);
		pre = pre+'_o.gif';
		preload_image_object = new Image();
		preload_image_object.src = pre;
	});
	
	$('.date-pick').datePicker();
	
	$('#start-date').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				var selmonth = d.getMonth();
				if (selmonth == 11 || selmonth == 0 || selmonth == 1 || selmonth == 2) {
					$('#end-date').dpSetStartDate(d.addDays(3).asString());
				} else {
					$('#end-date').dpSetStartDate(d.addDays(1).asString());
				}
				$('#end-date').val(d.asString());
				
				//alert(d.asString());
			}
		}
	);
	
	$('#end-date').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#start-date').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
	
	$('#start-date').dpSetPosition($.dpConst.POS_BOTTOM, $.dpConst.POS_LEFT);
	$('#end-date').dpSetPosition($.dpConst.POS_BOTTOM, $.dpConst.POS_LEFT);
	
	
	$('#start-date2').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#end-date2').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	
	$('#end-date2').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#start-date2').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
	
	$('#start-date2').dpSetPosition($.dpConst.POS_BOTTOM, $.dpConst.POS_LEFT);
	$('#end-date2').dpSetPosition($.dpConst.POS_BOTTOM, $.dpConst.POS_LEFT);
	
	
	var path = location.pathname;
	//console.log(path);
	$('#quickmenuul a[@href$="' + path + '"]').addClass('active');
	
	/*
	if ($.isFunction($('#panel2')[0].scrollTo)) {
		$('#panel2')[0].scrollTo('.active');
	}
	*/
	
	$("ul.sf-menu").superfish({
							  	autoArrows: true
							  });

	
	//var cpage =$.jqURL.url();
	
		/* repleace url */		
		//path = path.replace('http://www.freshpowder.com','');	
		//path = path.replace('http://freshpowder.com','');	  	
	
	
	if(path == 'pages/furano/getting_there/plane') {			
		$('a[@href*="/pages/furano/getting-there/plane"]').addClass('active');
	} else if ((path.indexOf('calendars/index/2/1') >=1) ||
				(path == '/snowreports/index/1') ||
				(path == '/liftpasses/index/1') ||
				(path == '/guestbooks/index/1') ||
				(path == '/skihires/furando') ||
				(path == '/lessons/index/1'))  {
		 // furano menu
		$('a[@href*="/pages/furano/about-furano"]').addClass('active');
		 
	} else if ((path.indexOf('calendars/index/2/2') >=1) ||
				(path == '/snowreports/index/2') ||
				(path == '/liftpasses/index/2') ||
				(path == '/guestbooks/index/2') ||
				(path == '/skihires/niseko') ||
				(path == '/nisekolessons/index/1')) {
		/* niseko menu */		 
		$('a[@href*="/pages/niseko/"]').addClass('active');
		/*
	} else if ((path == '/pages/reservation/hot_deal') ||
				(path == '/pages/reservation/faq') ||
				(path == '/pages/reservation/terms-and-conditions') ||
				path == '/rest1s/dateform' ||
				(path == '/rest1s/availgrid')) {
		//reservation menu
		$('a[@href*="/rest1s/dateform"]').addClass('active');
		*/
		/*
	} else if ((path == '/pages/furano/about-furano/winter') ||
				(path =='/pages/furano/about-furano/summer')) {
		// furano winter & summer
		$('a[@href*="/pages/furano/about-furano"]').addClass('active');
		*/
		/*
	} else if ((path == '/pages/niseko/about-niseko/winter') ||
				(path =='/pages/niseko/about-niseko/summer')) {
		// niseko winter & summer
		$('a[@href*="/pages/niseko/about-niseko"]').addClass('active');
		*/
	} else if (path == '/pages/furano/snow_report') {
		$('a[@href*="/snowreports/index"]').addClass('active');
		/*
	} else if ((path == '/newsletters/index') ||
				(path == '/pages/information/employment')) {
		//information menu
		$('a[@href*="/homes/latestnew"]').addClass('active');
		*/
		/*
	} else if ((path == '/accommodations/photoindex/3') ||
				(path == '/accommodations/photoindex/1') ||
				(path == '/videogalleries/')) {
		//photo gallery
		$('a[@href*="/accommodations/photoindex/2"]').addClass('active');
		*/
	} else if (path == '/rest1s/dateconfirm' ||
			   path == '/rest1s/dateuser' ||
			   path == '/rest1s/reservrequest' ||
			   path == '/accommodations/select-accommodation') {
		$('a[@href*="/rest1s/online-booking"]').addClass('active');
	} else if (path == '/rest1s/dateform' ||
			   path == '/rest1s/availgrid') {
		$('a[@href*="/rest1s/dateform"]').addClass('active');
	} else if (path == '/') {
		$("#home").addClass('active');
	}
	
});
