﻿$(document).ready(function() {

	/* onmouseover and onmouseout script */
	/* TOP Menu */
	$("#main_navigation ul li").mouseenter(function() {
		$(this ).css('background-image','url(/assets/templates/hilton/layout/onstate.jpg)');
	});
	
	$("#main_navigation ul li").mouseleave(function() {
		if($(this).hasClass('active')!= true) $(this).css('background-image','url(/assets/templates/hilton/layout/offstate.jpg)');
	});

/* show tabs testing */
/*	$(".infotabs").mouseenter(function() {
		$(this).css('background-image','url(/assets/templates/hilton/layout/onstate.jpg)');
	});
	
	$(".infotabs").mouseleave(function() {
		$(this).css('background-image','url(/assets/templates/hilton/layout/offstate.jpg)');
	});*/

	$(".infotabs, .infotabslast").mouseenter(function() {
		if($(this).hasClass('active')!= true) {
			$(this).addClass('current');
		}
	});
	$(".infotabs, .infotabslast").mouseleave(function() {
		if($(this).hasClass('active')!= true) {
			$(this).removeClass('current');
		}
	});
	
	$(".infotabs, .infotabslast").click(function() {
		button_id='#'+$(this).attr('id');
		$(".infotabs, .infotabslast").each(function() {
			if($(this).hasClass('active')==true) {
				$(this).removeClass('active');
			}
			if($(this).hasClass('current')==true) {
				$(this).removeClass('current');
			}
		});
		$(button_id).addClass('active');
	});
	

/* end testing */

/* information sub Tabs */
/* Soci Sub Tabs */
	$('#socinext').click(function() {
			$('#vantagitab1').fadeOut('slow',function(){
				$('#vantagitab2').fadeIn('slow');
			});
	});

	$('#socinext2').click(function() {
			$('#vantagitab2').fadeOut('slow',function(){
				$('#vantagitab3').fadeIn('slow');
			});
	});
	$('#sociback').click(function() {
			$('#vantagitab2').fadeOut('slow',function(){
				$('#vantagitab1').fadeIn('slow');
			});
	});
	
	$('#sociback2').click(function() {
			$('#vantagitab3').fadeOut('slow',function(){
				$('#vantagitab2').fadeIn('slow');
			});
	});

/* Partners Sub Tabs */	
	$('#partnernext').click(function() {
			$('#partnertab1').fadeOut('slow',function(){
				$('#partnertab2').fadeIn('slow');
			});
	});

	$('#partnernext2').click(function() {
			$('#partnertab2').fadeOut('slow',function(){
				$('#partnertab3').fadeIn('slow');
			});
	});
	$('#partnerback').click(function() {
			$('#partnertab2').fadeOut('slow',function(){
				$('#partnertab1').fadeIn('slow');
			});
	});
	
	$('#partnerback2').click(function() {
			$('#partnertab3').fadeOut('slow',function(){
				$('#partnertab2').fadeIn('slow');
			});
	});
/* Punti Sub Tabs */
	$('#puntinext').click(function() {
			$('#puntitab1').fadeOut('slow',function(){
				$('#puntitab2').fadeIn('slow');
			});
	});

	$('#puntinext2').click(function() {
			$('#puntitab2').fadeOut('slow',function(){
				$('#puntitab3').fadeIn('slow');
			});
	});
	$('#puntinext3').click(function() {
			$('#puntitab3').fadeOut('slow',function(){
				$('#puntitab4').fadeIn('slow');
			});
	});
	$('#puntiback').click(function() {
			$('#puntitab2').fadeOut('slow',function(){
				$('#puntitab1').fadeIn('slow');
			});
	});
	
	$('#puntiback2').click(function() {
			$('#puntitab3').fadeOut('slow',function(){
				$('#puntitab2').fadeIn('slow');
			});
	});

	$('#puntiback3').click(function() {
			$('#puntitab4').fadeOut('slow',function(){
				$('#puntitab3').fadeIn('slow');
			});
	});
	
/* Events Bonus Sub Tabs */	
	$('#eventsnext').click(function() {
			$('#eventstab1').fadeOut('slow',function(){
				$('#eventstab2').fadeIn('slow');
			});
	});

	$('#eventsback').click(function() {
			$('#eventstab2').fadeOut('slow',function(){
				$('#eventstab1').fadeIn('slow');
			});
	});

/* Livelli Sub Tabs */	
	$('#livellinext').click(function() {
			$('#livellitab1').fadeOut('slow',function(){
				$('#livellitab2').fadeIn('slow');
			});
	});

	$('#livelliback').click(function() {
			$('#livellitab2').fadeOut('slow',function(){
				$('#livellitab1').fadeIn('slow');
			});
	});

/* End Informations sub tabs */
/* Information Top Tabs */

/* Introduzione */
	$('#infotab_0').click(function() {
		document.mastimage.src='/assets/images/italia/infoimage2.jpg';
		document.getElementById('trans_text').innerHTML ='Doubletree by Hilton Acaya Golf Resort Lecce';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#introduzione').fadeIn('slow');
				}); 
			}
	});
	
/* Vantagi Soci */		
	$('#infotab_1').click(function() {
		document.mastimage.src='/assets/images/italia/infoimage8.jpg';
		document.getElementById('trans_text').innerHTML ='Molino Stucky Hilton Venice';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#vantagitab2').fadeOut('slow');
					$('#vantagitab3').fadeOut('slow');
				}); 
			}
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#vantaggi').fadeIn('slow');
				}); 
			}
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#vantagitab1').fadeIn('slow');
				}); 
			}
	});

/* Livelli */		
	$('#infotab_2').click(function() {
		document.mastimage.src='/assets/images/italia/infoimage3.jpg';
		document.getElementById('trans_text').innerHTML ='Doubletree by Hilton Resort Kos – Helona, Greece';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#livellitab2').fadeOut('slow');
				}); 
			}
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#livelli').fadeIn('slow');
				}); 
			}
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#livellitab1').fadeIn('slow');
				}); 
			}
	});

/* HHonors Partner */	
	$('#infotab_3').click(function() {
		document.mastimage.src='/assets/images/italia/infoimage4.jpg';
		document.getElementById('trans_text').innerHTML ='Hampton Inn Manhattan – SoHo, New York';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#partnertab2').fadeOut('slow');
					$('#partnertab4').fadeOut('slow');
					$('#partnertab3').fadeOut('slow');
				}); 
			}

			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#partners').fadeIn('slow');
				}); 
			}

			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#partnertab1').fadeIn('slow');
				}); 
			}
	});

/* Conversione Punti */	
	$('#infotab_4').click(function() {
		document.mastimage.src='/assets/images/italia/infoimage5.jpg';
		document.getElementById('trans_text').innerHTML ='Hilton Head Island, South Carolina';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#puntitab2').fadeOut('slow');
					$('#puntitab4').fadeOut('slow');
					$('#puntitab3').fadeOut('slow');
				}); 
			}
		
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#punti').fadeIn('slow');
				}); 
			}

			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#puntitab1').fadeIn('slow');
				}); 
			}
			
	});	
/* HHonors Info */	
	$('#infotab_5').click(function() {
		document.mastimage.src='/assets/images/italia/infoimage6.jpg';
		document.getElementById('trans_text').innerHTML ='Hilton Luxor Resort & Spa, Egypt';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#hhonorinfo').fadeIn('slow');
				}); 
			}
	});
/* Events Bonus */	
	$('#infotab_6').click(function() {
		document.mastimage.src='/assets/images/italia/infoimage7.jpg';
		document.getElementById('trans_text').innerHTML ='Hilton Dalaman Resort & Spa, Turkey';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#eventstab2').fadeOut('slow');
				}); 
			}
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#eventsbonus').fadeIn('slow');
				}); 
			}
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#eventstab1').fadeIn('slow');
				}); 
			}
	});
	
/* end Information Top tabs */
		
	$('#mapid_1').cluetip({activation: 'click', width: 185, sticky: true, closePosition: 'title', arrows: true, onShow: function() {
		/* $('#milanmalpensa').bind('click',function() {document.mastimage.src='/assets/images/italia/milanmalpensa.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_2').fadeIn('slow');
				}); 
			}
		}); */
		$('#hiltonmilan').bind('click',function() {document.mastimage.src='/assets/images/italia/milanhilton.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_2').fadeIn('slow');
				}); 
			}
		});
		$('#doublemilan').bind('click',function() {document.mastimage.src='/assets/images/italia/milandoubletree.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_3').fadeIn('slow');
				}); 
			}
		});
	}})

	$('#mapid_2').cluetip({activation: 'click', width: 185, sticky: true, closePosition: 'title', arrows: true, onShow: function() {
		$('#venicemestre').bind('click',function() {document.mastimage.src='/assets/images/italia/venicegardininn.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_0').fadeIn('slow');
				}); 
			}
		});

		$('#molinostucky').bind('click',function() {document.mastimage.src='/assets/images/italia/venicemolino.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_1').fadeIn('slow');
				}); 
			}
		});
	}})

	$('#mapid_4').cluetip({activation: 'click', width: 185, sticky: true, closePosition: 'title', arrows: true, onShow: function() {
		$('#florencemetro').bind('click',function() {document.mastimage.src='/assets/images/italia/florencemetropole.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_5').fadeIn('slow');
				}); 
			}
		});
		$('#florencenovo').bind('click',function() {document.mastimage.src='/assets/images/italia/florencenovoli.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_6').fadeIn('slow');
				}); 
			}
		});
	}})

	$('#mapid_5').cluetip({activation: 'click', width: 185, sticky: true, closePosition: 'title', arrows: true, onShow: function() {
		$('#romecaval').bind('click',function() {document.mastimage.src='/assets/images/italia/romecaveleri.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_7').fadeIn('slow');
				}); 
			}
		});
		$('#hiltonairport').bind('click',function() {document.mastimage.src='/assets/images/italia/romeairport.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_8').fadeIn('slow');
				}); 
			}
		});
		$('#gardenairport').bind('click',function() {document.mastimage.src='/assets/images/italia/gardininn.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_9').fadeIn('slow');
				}); 
			}
		});
	}})

	$('#mapid_12').cluetip({activation: 'click', width: 185, sticky: true, closePosition: 'title', arrows: true, onShow: function() {
		$('#hiltonpalermo').bind('click',function() {document.mastimage.src='/assets/images/italia/palermoexe.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_18').fadeIn('slow');
				}); 
			}
		});
		$('#hiltonigiea').bind('click',function() {document.mastimage.src='/assets/images/italia/palermovilla.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_17').fadeIn('slow');
				}); 
			}
		});
	}})
	
	/* Italy Map Section single links */
	
	$('#mapid_3').click(function() {
		document.mastimage.src='/assets/images/italia/lazaro.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_4').fadeIn('slow');
				}); 
			}
	});
	
	$('#mapid_6').click(function() {
		document.mastimage.src='/assets/images/italia/olbia.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_10').fadeIn('slow');
				}); 
			}
	});
	$('#mapid_7').click(function() {
		document.mastimage.src='/assets/images/italia/sorrento.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_11').fadeIn('slow');
				}); 
			}
	});
	$('#mapid_8').click(function() {
		document.mastimage.src='/assets/images/italia/bari.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_12').fadeIn('slow');
				}); 
			}
	});
	$('#mapid_9').click(function() {
		document.mastimage.src='/assets/images/italia/lecce.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_14').fadeIn('slow');
				}); 
			}
	});
	$('#mapid_10').click(function() {
		document.mastimage.src='/assets/images/italia/matera.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_15').fadeIn('slow');
				}); 
			}
	});
	$('#mapid_11').click(function() {
		document.mastimage.src='/assets/images/italia/acaya.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_13').fadeIn('slow');
				}); 
			}
	});
	$('#mapid_13').click(function() {
		document.mastimage.src='/assets/images/italia/giardini.jpg';
			id='';
			$('.infotabshow').each(function() {
				if($(this).css('display')!='none') id=$(this).attr('id');
			});
			if(id!='') {
				$('#'+id).fadeOut('slow',function() {
					$('#maparea_16').fadeIn('slow');
				}); 
			}
	});


	
	$("#cluetip-inner p a").mouseenter(function() {
		$(this ).css('color:','#000000');
	});
	
	$("#cluetip-inner p a").mouseleave(function() {
		if($(this).hasClass('active')!= true) $(this).css('color:','#ffffff');
	});

		/* end map section */
	/*Custom select boxes*/
	
	$('form#resForm select')
	.styledSelect({
	}).parents('form').show();
	
	
	//$(".homeleftcopy").jScrollPane();
	
	
	/**********   Datepicker for booking widget **********/
/**********   Datepicker for booking widget **********/
	$(function() {
		$('#linkedDatepicker')
			.datepicker({
				dateFormat: 'dd/mm/yy',
				beforeShow: readLinked,
				onSelect: updateLinked,
				showOtherMonths:false,
				selectOtherMonths:false,
				mandatory: true,
				changeMonth: false,
				changeYear: false, 
				minDate: '+0D',
				maxDate: '+1Y',
				showOn: 'both', buttonImageOnly: true, buttonImage: '/assets/templates/hilton/layout/icon_calendar.gif'}); 
		 
		// Prepare to show a date picker linked to three select controls  
		function readLinked() {  
			$('#linkedDatepicker').val( $('#checkin_day').val() + '/' + $('#checkin_month_year').val()  );
			
			/*extra stuff for custom select*/
			$('#datepicker1 li').attr({ rel : $('#arrival2 li').attr('rel') + '/' + $('#arrival1 li').attr('rel') });
			
			return {};  
		}  
	  
		// Update three select controls to match a date picker selection  
		function updateLinked(date) { 
			$('#checkin_month_year').val(	date.substring(3, 11) );  
			$('#checkin_day').val(	date.substring(0, 2)	);			
			/*lock checkin with checkout*/
			$('#checkout_month_year').val(	date.substring(3, 11) );  
			$('#checkout_day').val(	date.substring(0, 2)	); 
			
			/*extra stuff for custom select*/
			$('#arrival1 li').html( $('#checkin_month_year :selected').text() ).attr({rel : date.substring(3, 11) });    
			$('#arrival2 li').html( date.substring(0, 2)).attr({rel : date.substring(0, 2)	}); 
			/*lock checkin with checkout*/
			$('#departure1 li').html( $('#checkout_month_year :selected').text() ).attr({rel : date.substring(3, 11) });    
			$('#departure2 li').html( date.substring(0, 2)).attr({rel : date.substring(0, 2)	});
		}
		
		$('#linkedDatepicker2')
			.datepicker({
				dateFormat: 'dd/mm/yy',
				beforeShow: readLinked2,
				onSelect: updateLinked2,
				showOtherMonths:false,
				selectOtherMonths:false,
				mandatory: true,
				changeMonth: false,
				changeCurrent:false,
				changeYear: false,
				minDate: '+1D',
				maxDate: '+1D +1Y', 
				showOn: 'both', buttonImageOnly: true, buttonImage: '/assets/templates/hilton/layout/icon_calendar.gif'}); 
		
		 
		// Prepare to show a date picker linked to three select controls  
		function readLinked2(input, inst) {
			var minday = $('#checkin_day').val();
			var minmonth = ( $('#checkin_month_year').val() ).substring(0,2);
			var minyear = ( $('#checkin_month_year').val() ).substring(3,8);			

			$('#linkedDatepicker2').val( $('#checkout_day').val() + '/' + $('#checkout_month_year').val()  );
			
			/*extra stuff for custom select*/
			$('#datepicker2 li').attr({ rel : $('#departure2 li').attr('rel') + '/' + $('#departure1 li').attr('rel') });
			
			return {minDate:new Date(minyear, minmonth-1, minday)};			
		}  
	  
		// Update three select controls to match a date picker selection  
		function updateLinked2(date) { 
			$('#checkout_month_year').val(	date.substring(3, 11) );  
			$('#checkout_day').val(	date.substring(0, 2)	); 
			
			/*extra stuff for custom select*/
			$('#departure1 li').html( $('#checkout_month_year :selected').text() ).attr({rel : date.substring(3, 11) });    
			$('#departure2 li').html( date.substring(0, 2)).attr({rel : date.substring(0, 2)	}); 			
		}
	});	
	/**********   Booking date selection fix - set checkout when settinch checkin **********/
	$('#arrival1').blur(function(){
		alert('change');
	});

/* End Date Picker */	

	/*photo popup*/
/*	$("a[rel='minigal_rotate']").colorbox({width:"645px", height:"434px"});*/

	
	
});


/*
 * jQuery Styled Select Boxes
 * version: 1.1 (2009/03/24)
 * @requires jQuery v1.2.6 or later
 *
 * Examples and documentation at: http://code.google.com/p/lnet/wiki/jQueryStyledSelectOverview
 *
 * Copyright (c) 2008 Lasar Liepins, liepins.org, liepins@gmail.com
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */
jQuery.fn.styledSelect=function(settings){settings=jQuery.extend({selectClass:'styledSelect',openSelectClass:'open',optionClass:'option',selectedOptionClass:'selected',closedOptionClass:'closed',firstOptionClass:'first',lastOptionClass:'last',zIndexApply:false,zIndexStart:250,deactiveOnBackgroundClick:true},settings);var currentZIndex=settings.zIndexStart;this.each(function(){var s=jQuery(this);var cs=jQuery('<div></div>').attr('class',settings.selectClass);if(settings.zIndexApply){cs.css('z-index',currentZIndex-2);};var csl=jQuery('<ul></li>');if(settings.zIndexApply){csl.css('z-index',currentZIndex-1);};cs.append(csl);s.hide(0).after(cs);cs=s.next();jQuery('option',s).each(function(){if(jQuery(this).attr('value')==undefined){jQuery(this).attr('value',jQuery(this).text());}});var closedSelect=function(){jQuery('ul',cs).html('');addOption(s.val(),jQuery(':selected',s).text(),clickSelect);cs.removeClass(settings.openSelectClass);jQuery('ul li',cs).removeClass(settings.selectedOptionClass).removeClass(settings.optionClass).addClass(settings.closedOptionClass);if(settings.deactiveOnBackgroundClick){$(document).unbind('mousedown',closedSelect);cs.unbind('mousedown');}};var clickSelect=function(){jQuery('ul',cs).empty();jQuery('option',s).each(function(i){addOption(jQuery(this).val(),jQuery(this).text(),clickOption);});cs.addClass(settings.openSelectClass);jQuery('ul li:first-child',cs).addClass(settings.firstOptionClass);jQuery('ul li:last-child',cs).addClass(settings.lastOptionClass);if(settings.deactiveOnBackgroundClick){$(document).bind('mousedown',closedSelect);cs.bind('mousedown',function(){return false;});}};var clickOption=function(){var val=jQuery(this).attr('rel');s.val(val);closedSelect();};var addOption=function(optVal,optName,callBack){var cso=jQuery('<li></li>').attr('rel',optVal).text(optName).click(callBack).addClass(settings.optionClass);if(settings.zIndexApply){cso.css('z-index',currentZIndex);};if(s.val()==optVal){cso.addClass(settings.selectedOptionClass);};jQuery('ul',cs).append(cso);};closedSelect();s.change(closedSelect);currentZIndex-=3;});return this;};
