 $(document).ready(function(){

	// z-index layering fix for IE7
	var zIndexNumber = 10000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});

	$("a[rel^='prettyPhoto']").prettyPhoto({ 
		theme: 'dark_rounded',
		autoplay: true
	
	});
 	
    $('.blink').
        focus(function() {
            if(this.title==this.value) {
                this.value = '';
            }
        }).
        blur(function(){
            if(this.value=='') {
                this.value = this.title;
            }
        });
		
	$('.scroll').jScrollPane();
	$('.text-box-scroll').jScrollPane();
	

	/** Custom Select **/
	$('.custom-select').each(function(){
		var options = $(this).find('option');
		
		var selected_value = options.eq(0).html();
		
		var options_html = '';
		options.each(function(){
			options_html += '<li>' + $(this).html() + '</li>';
			if($(this).attr('selected'))
				selected_value = $(this).html();
		});
		
		var w = (parseInt($(this).css('width')) + 4) + 'px';
		var html = '';
		html += '<div class="select" style="width:'+w+'">';
		html += '<div class="select-head"><div class="select-value">' + selected_value + '</div></div>';
		html += '<div class="select-dd"><ul>';
		html += options_html;
		
		html += '</ul></div></div>';
		
		$(this).wrap('<div class="custom-select-holder">');
		$(this).before( html );
		
	});
	$('.select-value').click(function(e){
		var parent = $(this).parent().parent();
		var select_dd = parent.find('.select-dd');
		
		
		
		if( select_dd.css('display') == 'none') {
			$('.custom-select-holder').css({ 'z-index': 10 });
			$('.select-dd').hide();
			
			select_dd.show();
			parent.parent().css({ 'z-index': 100 });	
		}else {
			select_dd.hide();
			
		}
		
		
		$('body').click(function(){ 
			$('.custom-select-holder').css({ 'z-index': 10 });
			$('.select-dd').hide();
		});
		
		return false;
	});
	
	$('.select-dd').each(function(){
		var i=0;
		$(this).find('li').each(function(){
			this._index = i;
			i++;
		});
	})
	
	$('.select-dd li').click(function(){
		var parent = $(this).parent().parent().parent();
		var value = $(this).html();
		var index = this._index;
		var holder = parent.parent();
		
		parent.find('.select-value').html(value);
		parent.find('.select-dd').hide();
		
		holder.find('option').attr({ 'selected' : false });
		holder.find('option:eq('+index+')').attr({ 'selected' : true });
		
		return false;
	});	

	$('#video-2').hide();
	$('#video-3').hide();
	$('#video-4').hide();
	
	$('#video-link-1').click(function() {
		$('#video-1').fadeIn(1000);
		$('#video-2').hide();
		$('#video-3').hide();
		$('#video-4').hide();
		$('.pagination a').removeClass('pagination-active');
		$('#video-link-1').addClass('pagination-active');
	});
	$('#video-link-2').click(function() {
		$('#video-2').fadeIn(1000);
		$('#video-1').hide();
		$('#video-3').hide();
		$('#video-4').hide();
		$('.pagination a').removeClass('pagination-active');
		$('#video-link-2').addClass('pagination-active');
	});
	$('#video-link-3').click(function() {
		$('#video-3').fadeIn(1000);
		$('#video-1').hide();
		$('#video-2').hide();
		$('#video-4').hide();
		$('.pagination a').removeClass('pagination-active');
		$('#video-link-3').addClass('pagination-active');
	});
	$('#video-link-4').click(function() {
		$('#video-4').fadeIn(1000);
		$('#video-1').hide();
		$('#video-2').hide();
		$('#video-3').hide();
		$('.pagination a').removeClass('pagination-active');
		$('#video-link-4').addClass('pagination-active');
	});
	
	
});
 
 function openMap(address) {
	var zip = $('#polling-zipcode').val();
	
	window.open('http://maps.google.com/maps?f=q&source=s_q&hl=en&q=from:' + zip + '+to:' + address,'name','options');
	return false;
}

