function setCookie (name,value,days)
{
    if (days) {
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(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 deleteCookie(name) {
	setCookie(name,"",-1);
}
	
$(function(){
$("#BedBr-btn").click(function(){
    setCookie("BedBreakfast","clicked");
    window.location='/Plan-Your-Visit/Accommodations';
    
});
//right block email
$('#right_col .join_f input.email').each( function(ind, el){
	$(el).addClass('intput-clear');
	$(el).attr('alt', $(this).attr('value'));
});
$('html').click( function(e){
	$('#right_col .join_f input.email').each( function(ind, el){
		if( !$(el).hasClass('intput-clear') && $.trim($(this).attr('value'))=='' && e.target != el){
			$(el).addClass('intput-clear');
			$(el).attr('value', $(this).attr('alt'));
		}
	});
});
$('#right_col .join_f input.email').click(function(){
	if($(this).hasClass('intput-clear')){
		$(this).attr('value', '');
		$(this).removeClass('intput-clear');
	}
});


// home page view more
	$('#welcome a.more').toggle(
		function(){
			$('#welcome .hp_more_content').slideDown()
			$(this).html('&ndash; View less')
		},
		function(){
			$('#welcome .hp_more_content').slideUp()
			$(this).html('+ View more')
		}
	)
	
// featured events scrollable
    var miniControls = $('.mini_controls');
    $(miniControls).each(function(){
	    var eii = $(this).parent().find('.events_items .items').html();
	    eii = jQuery.trim(eii);
	    if ((eii != null) && (eii != 'undefined') && (eii != '')) {
	      $(this).parent().find('.events_items').scrollable({
		      circular: true,
		      prev: '.prev_fe',
		      next: '.next_fe'
	      })
	    }
    });



// list of features


// blog feed scrollable
	var sffii = $('.scrollable_feeds .feed_items .items').html();
	sffii = jQuery.trim(sffii);
	if ((sffii != null) && (sffii != 'undefined') && (sffii != '')) {
	$('.scrollable_feeds .feed_items').scrollable({
		prev: '.prev_bf',
		next: '.next_bf'
	})
	}

//blog feed tabs
	$('a.fs').click(function(){
		$('.feeds ul li').removeClass('active');
		$(this).parent('li').addClass('active');
		$('.feed_items').hide();
        $('.controls_feed').hide();
		var tab_id = $(this).attr('id');
		$('div.'+tab_id).show();
		return false;
	});

//rotating features
//	var rci = $('.rf_container .items').html();
//	rci = jQuery.trim(rci);
//	if ((rci != null) && (rci != 'undefined') && (rci != '')) {
//	$('.rf_container').scrollable({
//		circular: true,
//		prev: '.rot_left',
//		next: '.rot_right'
//	}).autoscroll({interval: 8000});
//	}

    var rciCont = $('.rf_container');
    $(rciCont).each(function(){
	    var rci = $(this).find('.items').html();
	    rci = jQuery.trim(rci);
	    if ((rci != null) && (rci != 'undefined') && (rci != '')) {
	        $(this).scrollable({
		        circular: true,
		        prev: '.rot_left',
		        next: '.rot_right'
	        }).autoscroll({interval: 8000});
	    }
    });



//events popup scrollable
	var peii = $('.popup_event_items .items').html();
	peii = jQuery.trim(peii);
	if ((peii != null) && (peii != 'undefined') && (peii != '')) {
	$('.popup_event_items').scrollable({
		prev: '.pop_prev',
		next: '.pop_next'
	})
	}

//media player scrollable
	var mpi = $('.media_player .items').html();
	mpi = jQuery.trim(mpi);
	if ((mpi != null) && (mpi != 'undefined') && (mpi != '')) {
		$('.media_player')
			.scrollable({
				circular: true,
				prev: '.media_prev',
				next: '.media_next'
			})
	}

//more videos scrollable
	var indexes_count = $('#indexes_count').val();

	if ((indexes_count > 0) && (indexes_count < 3)) {
		$('.more_videos_prev').hide();
		$('.more_videos_next').hide();
	} else {
		var mvsi = $('.more_videos_scrollable .items').html();
		mvsi = jQuery.trim(mvsi);
		if ((mvsi != null) && (mvsi != 'undefined') && (mvsi != '')) {
		$('.more_videos_scrollable').scrollable({
			circular: true,
			prev: '.more_videos_prev',
			next: '.more_videos_next'
		}).autoscroll({interval: 8000});
		}
	}

//interior page more videos - open/close
	$('.more_videos').click(function(){
		$('.more_videos_box').show();
  		$(".more_videos_next").click();
  		$(".more_videos_prev").click();
		return false;
	});
	$('.more_videos_close').click(function(){
		$('.more_videos_box').hide();
		return false;
	});

//destination wine country tabs
	$('.wine_dest_tabs li a').click(function(){
		$('.wine_dest_tabs li').removeClass('active');
		$(this).parent('li').addClass('active');
		/*$('.wine_dest').hide();
		var tab_id = $(this).attr('id');
		$('div.'+tab_id).show();
		return false;*/
	});

//datepicker
	$('#start_date, #end_date').datepicker();
	$('#book_start_date').datepicker({
		minDate: +0
	});
	$('#book_end_date').datepicker({
		minDate: +0,
		dafaultDate: +7
	});

// share popup
	$('.close_share').click(function(){
		$('.share_pop').slideUp();
	});
	$('.share').click(function(){
		$('.share_pop').slideDown();
		return false;
	});


//input field - initial value
	var input_initial = $('#input_initial').val();
	$('#input_initial').focusin(function(){
		if ($(this).val() == input_initial) {
			$(this).val('');
		}
	});
	$('#input_initial').focusout(function(){
		if ($(this).val() == '') {
			$(this).val(input_initial);
		}
	});

//start address - initial value
	var start_address = $('#start_address').val();
	$('#start_address').focusin(function(){
		if ($(this).val() == start_address) {
			$(this).val('');
		}
	});
	$('#start_address').focusout(function(){
		if ($(this).val() == '') {
			$(this).val(start_address);
		}
	});
//search box - initial value
	var wine_search = $('#wine_search').val();
	$('#wine_search').focusin(function(){
		if ($(this).val() == wine_search) {
			$(this).val('');
		}
	});
	$('#wine_search').focusout(function(){
		if ($(this).val() == '') {
			$(this).val(wine_search);
		}
	});


$('.fpo_video_close')
// see tiglou.css
	.css({
		position: 'absolute',
		width: 42,
		height: 24,
		top: 449,
		left: 1138,
		zIndex: 99999,
		cursor: 'pointer'
	})
	.click(function(){
		stop_c_player();

		//$('#jw-player_jwplayer').jwPlayer('stop');
		
		if(jQuery.browser.msie) {
				$('.hide_menus').animate({ height: 350 })
				$('#show_menu').animate({ height: 0 })
				$('.ha_video').slideUp(function(){ $('.logo img').attr('src', '/var/ezwebin_site/storage/images/design/loudoun/172-3-eng-GB/Loudoun.png') });
		} else {
				$('.hide_menus').animate({ height: 350, opacity: 1 })
				$('#show_menu').animate({ height: 0, opacity: 0 })
				$('.ha_video').slideUp(function(){ $('.logo img').attr('src', '/var/ezwebin_site/storage/images/design/loudoun/172-3-eng-GB/Loudoun.png') });
		}
	})

// events
	calendarRule  = '#calendar .ui-datepicker-current-day a {';
	calendarRule += 'position: relative; left: -8px; top: -9px; z-index: 99;';
	calendarRule += 'margin: 0 -50px -18px 0; padding: 11px 19px 11px 11px;';
	calendarRule += 'width: 29px; height: 17px;';
	calendarRule += 'color: #fff; }';

	// datepicker
	$("#calendar").datepicker({
		minDate: new Date(),
		altField: '.alt-date',
		altFormat: 'MM dd, yy',
		dateFormat: 'yy/mm/dd',
		onSelect: function(dateText, inst) {
			if($('style[title="calendar"]').length < 1) {
				$('<style title="calendar" type="text/css">'+calendarRule+'</style>').appendTo("body");
			}
			
			var el_class = $("#calendar").attr('class');
			
			if (el_class.indexOf("event_cal") == -1) {
				getEventsOnDate();
				
				$('#header').append($('.events_popup').detach());
				$('.events_popup').css({"top": "550px"});
				
				$('.events_popup')
					.find('.heading')
						.html('Events - '+$('.alt-date').val())
						.end()
					.find('.events_list')
	
				// you can load the events list here
				// dateText holds the selected date, formated with 'dateFormat' option
				// http://docs.jquery.com/UI/Datepicker/formatDate
		//			.load('events-list.html')
					.end()
					.fadeIn()
			} else {
				var cur_dt = getDatepickerDate('mm/dd/yy');
				var tmp_dt = cur_dt.split('/');
				cur_dt = tmp_dt[0] + '/' + tmp_dt[1] + '/' + tmp_dt[2];

				$("#start_date").val(cur_dt);
//				$("#end_date").val(cur_dt);

				//$(".search_tb").click();
				/*setWay("");
				var cur_search_post_url = getCurEventSearchPostUrl();
				var cur_limit = getCurEventLimit();

				GetEvents(cur_search_post_url, cur_limit);
				*/
				
				var start_date = $("#start_date").val();
//				var end_date = $("#end_date").val();
				var end_date = '';

				var locations = $("#locations").val();
				if (locations == '---Select location---') {
					locations = '';
				}
				var search_keyword1 = $("#search_keyword1").val();
				//var sort_by = $("#le_sort_by").val();
				var sort_by = ($("#le_sort_by").length > 0) ? $("#le_sort_by").val() : "-";
				var cb_checked = new Array();
				$('#events_search_form .event_categories_cb:checked').each(function(index, item){
					if ($(item) && ($(item) != null) && ($(item).val() != null)) {
						cb_checked.push($(item).val());
					}
				});
				
				var searchUrl = getCurEventSearchPostUrl();
				if (searchUrl.indexOf('Result') == -1) {
					searchUrl += '/Result';
				}
				var cur_limit = getCurEventLimit();
				var cur_offset = getCurEventOffset();
				var cur_show_poi_list = getCurShowPoiList();
				searchUrl += '/(limit)/' + cur_limit +
					'/(offset)/' + cur_offset +
					'/(show_poi_list)/' + cur_show_poi_list +
					'/(s_search)/' + 1 +
					'/(sort_by)/' + sort_by +
					'/(view_all)/' + 0 +
					'/(event_container_node)/' + 318 +
					'/(start_date)/' + start_date +
					'/(end_date)/' + end_date +
					'/(locations)/' + locations +
					'/(search_keyword1)/' + search_keyword1 +
					'/(cb_checked)/' + cb_checked.join('---')
				;
				window.location = searchUrl;
				
				return false;
			}
		}
	});
	
	$( document ).ready(
		function()
		{
			$("div.ui-datepicker-div td a").live( 'click',
				function()
				{
					return false;
				}
			);
		}
	);
	
// popup
	$('.events_popup .close').click(function(){
		$('.events_popup').fadeOut();
		$('style[title="calendar"]').remove();
		
		$(".ui-datepicker td").css({"background": "none repeat scroll 0 0 #FFFFFF"});
		$("#calendar .ui-datepicker-current-day a").css({"background": "none repeat scroll 0 0 #FFFFFF", "padding": "0.25em", left: "0px", "height": "0px"});
		var curdate = new Date();
		$("#calendar").datepicker('setDate',curdate);
		$("#calendar .ui-datepicker-current-day a").css({"background": "none repeat scroll 0 0 #CCCBAA", "padding": "0.25em", left: "0px", "height": "0px"});

		return false;
	})

// map popup
/*
function popup_stick() {
	$('#tvMapcontainer').live('mouseover.stick', function() {
		$(this).find('a.VEAPI_Pushpin > div').css({
			height: '35px',
			width: '35px'
		});
		$(this).find('#tvMap').one('mouseover', function() {
			var temp = $(this).find('a.VEAPI_Pushpin > div').attr('onmouseout');
			temp = temp.toString();
			temp = temp.replace('VEHideVEShapeERO(false);', 'setTimeout(function(){VEHideVEShapeERO(false);},2000);');
			$(this).find('a.VEAPI_Pushpin > div').attr('onmouseout', temp);
		});
		$('#tvMapcontainer').die('mouseover.stick');
	});
};
popup_stick();
*/
// map popup
$('a.VEAPI_Pushpin').live('mouseenter.stick', function() {
	$(this).find('> div').css({ height: '35px', width: '35px' });
	var temp = $(this).find('> div').attr('onmouseout');
	temp = temp.toString();
	temp = temp.replace('VEHideVEShapeERO(false);', 'setTimeout(function(){VEHideVEShapeERO(false);},2000);');
	$(this).find('> div').attr('onmouseout', temp);
});

// promo features carousell
	pfDelay = 6000;

	pfCurrent = 0;
	pfAnimating = false;
	pfCount = $('.promo_features img').length;
	pfWidth = 239;
	pfOffset = 25;
	// preload images

	$('body').append('<div class="preloadImgs" style="height: 0; overflow: hidden;"></div>')
	for (var i = pfCount; i--;) {
		$('.preloadImgs').append('<img class="pi'+i+'" src="'+$('.promo_features img:eq('+i+')').attr('src').replace(/\.jpg/, 'over.jpg')+'" />')
	}
	$('.pi0').load(function(){
		// auto rotate
		pfTimer = setInterval("pfShowNext(true)", pfDelay);
		$('.promo_features')
			.mouseenter(function(){ clearInterval(pfTimer) })
			.mouseleave(function(){ pfTimer = setInterval('pfShowNext(true)', pfDelay) })
		// manual rotate
		$('.pf_next')
			.animate({left: 940})
			.click(function(){ pfShowNext(false) })
		$('.pf_prev')
			.animate({left: 0})
			.click(function(){ pfShowPrev() })
		$('.preloadImgs').remove();
	})
	// hover states
	$('.promo_features .items a')
		.mouseenter(function(){
			$(this).find('img').attr('src', $(this).find('img').attr('src').replace('.jpg', 'over.jpg'))
		})
		.mouseleave(function(){
			$(this).find('img').attr('src', $(this).find('img').attr('src').replace('over.jpg', '.jpg'))
		})
	// set positions to absolute
		.each(function(){
			ind = $('.promo_features .items a').index($(this));
			leftPos = 13+(ind*pfWidth);
			if(ind>3) {
				leftPos += pfOffset;
			}
			$(this).css({
				position: 'absolute',
				top: 0,
				left: leftPos
			})
		})

// media tabs
	$('.media_tabs a, .media_player_wrp .feeds a').click(function(){
		
		ind = $('.media_tabs a, .media_player_wrp .feeds a').index($(this));

		$('.media_tabs li, .media_player_wrp li').removeClass('active');
		$(this).parent('li').addClass('active');

		$('.media_player_wrp .media_player').hide();
		$('.media_player_wrp .media_player:eq('+ind+')').show();

    countItems = $('.media_player_wrp .media_player:eq('+ind+')').find('.media_player_item:not(.cloned)').length;

    block = $(this).parents('div.media_player_wrp');
    if( countItems > 1 ) {
      block.children('.media_prev').show();
      block.children('.media_next').show();
      $('.media_next').click();
      $('.media_prev').click();
    } else {
      block.children('.media_prev').hide();
      block.children('.media_next').hide();
    }
    

		return false;
	})

  $('.media_player_wrp li.active a').click();

// show/hide the menu
	if(jQuery.browser.msie) {
		$('.hide_menu').click(function(){
			$('.hide_menus').css({overflow: 'hidden'}).animate({ height: 0 });
			$('#show_menu').animate({ height: 38 });
		})
		$('.show_menu').click(function(){
			$('.hide_menus').css({overflow: 'visible'}).animate({ height: 350 });
			$('#show_menu').animate({ height: 0 });
		})
	} else {
		$('.hide_menu').click(function(){
			$('.hide_menus').animate({ height: 0, opacity: 0 });
			$('#show_menu').animate({ height: 38, opacity: 1 });
		})
		$('.show_menu').click(function(){
			$('.hide_menus').animate({ height: 350, opacity: 1 });
			$('#show_menu').animate({ height: 0, opacity: 0 });
		})
	}

// subnav dropdown

	ntelem = $('body:not(.winecountry) #nav li.nav_trip')
	ntel = $('#nav li.nav_trip')
	$('#nav li.nav_trip a:first-child').click(function(){return false;});
	$("body:not(.winecountry) #nav > li:not(.nav_trip)")
		.mouseenter(function(){
			ntelem
				.removeClass('on')
				.css({zIndex: 20})
				.children(".main_subnav").css({left: -9999})
			$(this)
				.css({zIndex: 19})
				.children(".main_subnav").css({left: -13})
		})
		.mouseleave(function(){
			$(this)
				.css({zIndex: 20})
				.children(".main_subnav").css({left: -9999})
		})

	ntelem
		.mouseenter(function(){
			$(this)
				.addClass('on')
				.css({zIndex: 19})
				.children(".main_subnav ").css({left: -287})
		})
		.children('a')
			.mouseleave(function(){
				$(this).removeClass('clicked')
			})
			.click(function(){
				$(this).addClass('clicked')
//				ntelem.removeClass('on').css({zIndex: 20}).children(".main_subnav").css({left: -9999})
		})
		$('html').click(function(e){
			ntd1 = $(e.target).parents('.trip_btm').length
			ntd2 = $(e.target).parents('#ui-datepicker-div').length
			if($(e.target).hasClass('ui-icon') || $(e.target).hasClass('ui-datepicker') || $(e.target).hasClass('ui-datepicker-prev') || $(e.target).hasClass('ui-datepicker-next')) ntd2=1;
			if(!(ntd1 || ntd2)) {
				ntel
					.removeClass('on')
					.css({zIndex: 20})
					.children(".main_subnav").css({left: -9999})
			}
		})
		$('.trip_btm .close').click(function(){
				ntel
					.removeClass('on')
					.css({zIndex: 20})
					.children(".main_subnav").css({left: -9999})
		})

// winecountry subnav dropdown

	ntelem1 = $('body.winecountry #nav li.nav_trip')
	$("body.winecountry #nav > li:not(.nav_trip)")
		.mouseenter(function(){
			ntelem1
				.removeClass('on')
				.css({zIndex: 20})
				.children(".main_subnav").css({left: -9999})
			$(this)
				.css({zIndex: 19})
				.children(".main_subnav").css({left: -5})
			$(this)
				.children('a').css('background', 'none')
		})
		.mouseleave(function(){
			$(this)
				.css({zIndex: 20})
				.children(".main_subnav").css({left: -9999})
			$(this)
				.children('a').css('background', '#7C183E')
		})

	ntelem1
		.mouseenter(function(){
			$(this)
				.addClass('on')
				.css({zIndex: 19})
				.children(".main_subnav ").css({left: -258})
		})
		.children('a')
			.mouseleave(function(){
				$(this).removeClass('clicked')
			})
			.click(function(){
				$(this).addClass('clicked')
				ntelem1
					.removeClass('on')
					.css({zIndex: 20})
					.children(".main_subnav").css({left: -9999})
		})

// custom selectbox
	$(".styled, .tv_f select").customStyle();

//fancybox
	/*if($('a.play_video_button').length > 0) {
		$("a.play_video_button").fancybox({
			type: 'iframe',
			width: 783,
			height: 476,
			padding: 0,
			scrolling: 'no',
			'overlayOpacity' : 0.7,
			'overlayColor' : '#000'
		});
	}*/
//more categories slide
moreCat = false;
$('.cat_links a.more').click(function(){
	if(moreCat) {
		moreCat = false;
		$('.more_cat').slideUp();
	} else {
		moreCat = true;
		$('.more_cat').slideDown();
	} return false;
})
// view map slide
$('.view_map').data('sm', false)
$('.view_map').click(function(){
	if($(this).data('sm')) {
		$(this).data('sm', false);
 		$(this).text('View map');
		$(this).parents('.hh_item').find('.map_container').slideUp();
	} else {
		$('.view_map').data('sm', false)
		$('.map_container').slideUp();
		$(this).data('sm', true);
    parents = $(this).parents('div.hh_list');
    parents.find('a.view_map').text('View map');
    $(this).text('Close map');
		parents.find('.map_container').slideDown();
	} return false;
})

// button hover states
	jQuery.preLoadImages('/extension/nxc_tiglou/design/tiglou/images/structural/search_btn_over.gif', '/extension/nxc_tiglou/design/tiglou/images/structural/search_btn_w_over.gif', '/extension/nxc_tiglou/design/tiglou/images/structural/go_btn_over.gif', '/extension/nxc_tiglou/design/tiglou/images/structural/signup_btn_over.gif', '/extension/nxc_tiglou/design/tiglou/images/structural/search_txt_btn_over.gif', '/extension/nxc_tiglou/design/tiglou/images/structural/send_b_over.png', '/extension/nxc_tiglou/design/tiglou/images/structural/search_btn_wide_over.gif');
	$('.search_btn')
		.mouseenter(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/search_btn_over.gif'); })
		.mouseleave(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/search_btn.gif'); })
	$('.search_btn_w')
		.mouseenter(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/search_btn_w_over.gif'); })
		.mouseleave(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/search_btn_w.gif'); })
	$('#events_search input[type="image"], .nearby_wide_f input[type="image"], .nearby_f input[type="image"], .tv_directions_f input[type="image"], .tv_f input#search_btn')
		.mouseenter(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/go_btn_over.gif'); })
		.mouseleave(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/go_btn.gif'); })
	$('.email_signup')
		.mouseenter(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/signup_btn_over.gif'); })
		.mouseleave(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/signup_btn.gif'); })
	$('body:not(".home") #events_search_form:not(.search_btn_style_free) input[type="image"]:not(#search_btn), #booking input[type="image"]')
		.mouseenter(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/search_txt_btn_over.gif'); })
		.mouseleave(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/search_txt_btn.gif'); })
	$('.share_frm input[type="image"]')
		.mouseenter(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/send_b_over.png'); })
		.mouseleave(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/send_b.png'); })
	$('.tv_f input#search_btn_wide')
		.mouseenter(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/search_btn_wide_over.gif'); })
		.mouseleave(function(){ $(this).attr('src', '/extension/nxc_tiglou/design/tiglou/images/structural/search_btn_wide.gif'); })
});

// promo features carousell functions
function pfShowNext(auto){
	if(pfAnimating || pfCount < 5) return false;
	clearInterval(pfTimer);
	pfAnimating = true;
	pfNext = pfCurrent+4;
	pfNext %= pfCount;

	$('.promo_features .items a:lt('+pfNext+'):gt('+pfCurrent+'), .promo_features .items a:gt('+pfNext+'), .promo_features .items a:lt('+pfCurrent+')')
		.animate({left: '-='+(pfWidth)}, { queue: false });
	$('.promo_features .items a:eq('+pfNext+')')
	.animate({left: '-='+(pfWidth+pfOffset)}, { queue: false });
	$('.promo_features .items a:eq('+pfCurrent+')')
		.animate({
			left: '-='+(pfWidth+pfOffset)
		}, {
			queue: false,
			complete: function(){
				pfCurrent++;
				pfCurrent %= pfCount;
				pfAnimating = false;
				$(this).css({
					left: 13+((pfCount-1)*pfWidth)+pfOffset
				})
				if(auto) {
					pfTimer = setInterval('pfShowNext(true)', pfDelay);
				}
			}
		});
}
function pfShowPrev(){
	if(pfAnimating || pfCount < 5) return false;
	clearInterval(pfTimer);
	pfAnimating = true;
	pfNext = pfCurrent-1;
	if (pfNext<0) {
		pfNext = (pfCount-1);
	}
	pfRightmost = pfCurrent+3;
	pfRightmost %= pfCount;
	if(pfCurrent == 0) {
		$('.promo_features .items a:eq(0)')
		.animate({left: '+='+(pfWidth)}, {queue: false});
	}
	$('.promo_features .items a:lt('+pfNext+'):gt('+pfCurrent+'), .promo_features .items a:gt('+pfNext+'), .promo_features .items a:lt('+pfCurrent+')')
		.animate({left: '+='+(pfWidth)}, {queue: false});
	$('.promo_features .items a:eq('+pfNext+')')
		.css({left: (-pfOffset-pfWidth)})
		.animate({left: 13}, {queue: false});
	$('.promo_features .items a:eq('+pfRightmost+')')
		.animate({
			left: '+='+(pfWidth+pfOffset)
		}, {
			queue: false,
			complete: function(){
				pfCurrent--;
				if (pfCurrent<0) {
					pfCurrent = (pfCount-1);
				}
				pfAnimating = false;
			}
		});
}

// preload images
(function($) {
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery)

// Cufon text replacement
	Cufon.replace('.cufon');

function lightBoxSetContent(content, widthContent, heightContent) {
	//stop_c_player();
	
	$(".onPagePlayer").css("width", parseInt(widthContent) + 10);
	$(".onPagePlayer").css("height", parseInt(heightContent));
	
	$(".onPagePlayerBorder").css("height", 'auto');
	$("#onPagePlayerBody").css("height", 'auto');

	$("#onPagePlayerBody").html(content);
	var docWidth = $(document).width();
	$("#onPagePlayerShadow").css("height", $(document).height());
	$("#onPagePlayerShadow").css("width", docWidth);
	$("#onPagePlayerShadow").show();
	$(".onPagePlayerHolder").css("width", docWidth);
	$(".onPagePlayerHolder").show();
	if($('embed').attr("id") == 'video360Embed'){
		$("#video360copyright").show();
	    var onPagePlayerLeft = $("#onPagePlayerBody").position().left + $("#onPagePlayerBody").outerWidth() - 40;
	    var onPagePlayerTop = $("#onPagePlayerBody").position().top + $("#onPagePlayerBody").outerHeight() - 40 + 4;
	    $("#full_screen_btn_holder").css({"left": onPagePlayerLeft, "top": onPagePlayerTop});
		$("#full_screen_btn_holder").show();
	}
	window.scrollTo(0,0);
	$(".onPagePlayer").css({
		"height":parseInt(heightContent),
		"width": parseInt(widthContent) + 10
	});
	//stop_c_player();
	//play_c_player();
}

function lightBoxSetContentShort(content, widthContent, heightContent) {
	//stop_c_player();
	
	$(".onPagePlayer").css("width", parseInt(widthContent) + 10);
	$(".onPagePlayer").css("height", parseInt(heightContent));
	$(".onPagePlayerBorder").css("height", 'auto');

	$("#onPagePlayerBody").css({"height":'auto'});
	
	var onPagePlayerLeft = $("#head_area").position().left;
	var onPagePlayerTop = $("#head_area").position().top;
	$("#onPagePlayerBody").css({"left": onPagePlayerLeft, "top": onPagePlayerTop});
	
	if(jQuery.browser.msie) {
		//$("#onPagePlayerBody").css({"height":'auto', 'left': '335'});
	}

	$("#onPagePlayerBody").html(content);
	var docWidth = $(document).width();
	$(".onPagePlayerHolder").css("width", docWidth);
	
	var fpo_video_close = document.getElementById('fpo_video_close');
	if ((fpo_video_close != null) && (fpo_video_close != 'undefined')) {
		$(".onPagePlayerBody").insertBefore('.fpo_video_close');
		
		//$(".fpo_video_close").insertAfter('.onPagePlayerBody');
	} else {
		$(".onPagePlayerBody").insertBefore('#head_area');
		var onPagePlayerLeft = $(".onPagePlayerBody").position().left;
		var onPagePlayerTop = $(".onPagePlayerBody").position().top;
		$('<div id="fpo_video_close" class="fpo_video_close" onclick="javascript: close_c_player();" style="position: absolute; width: 42px; height: 24px; top: 430px; left: 1119px; z-index: 99999; cursor: pointer;"><div class="fpo_video_close_text style="font-size: 91%;""><i>Close</i>&nbsp;<b>X</b></div></div>').insertAfter('.onPagePlayerBody');
		$('<div id="head_area_bottom_over_video"></div>').insertAfter('.onPagePlayerBody');
		$("#head_area_bottom_over_video").css({"left": onPagePlayerLeft - 11});
//		$(".fpo_video_close").css({"left": onPagePlayerLeft + 620, "top": onPagePlayerTop + 361 - 25});
		$(".fpo_video_close").css('left', onPagePlayerLeft + 695 - 42 - 17);
/*
		if (jQuery.browser.opera) {
			alert("opera");
			$(".fpo_video_close").css("left", "1144");
		}
		if (jQuery.browser.msie) {
			alert("IE");
			$(".fpo_video_close").css("left", "999");
		}
*/
	}

	$("#onPagePlayerBody").css({
		"height":parseInt(heightContent),
		"width":parseInt(widthContent),
		"position":"absolute",
		"z-index":"10",
		"padding":"0",
		"margin-left":"-11px"
	});
	$(".onPagePlayerHolder").hide();
	$("#head_area_bottom_over_video").show();

	//stop_c_player();
	show_c_player();
	//window.scrollTo(0,0);
}

function close_c_player()
{
	stop_c_player();
	$("#head_area_bottom_over_video").hide();
	$("#onPagePlayerBody").hide();
	$(".fpo_video_close").hide();
}

function show_c_player()
{
	$(".onPagePlayerBody").show();
	$(".fpo_video_close").show();
	//play_c_player();
}

function stop_c_player()
{
	if (jQuery.browser.safari) {
		$("#jw-player").remove();
	} else {
		if(jQuery.browser.msie) {
			if (jQuery.jwplayer() != null) {
				jQuery.jwplayer().stop;
				setTimeout(jQuery.jwplayer().stop, 100);
			}
		} else {
			if (jQuery.jwplayer() != null) {
				jQuery.jwplayer().stop;
				setTimeout(jQuery.jwplayer().stop, 100);
			}
		}
		
		var destroy_flag = $("#do_no_destroy_main_video").val();
		if ((destroy_flag != null) && (destroy_flag != undefined)) {
			;
		} else {
			$("#jw-player_jwplayer").remove();
		}
	}
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  
  if(jQuery.browser.msie) {
	  if (document.embeds && document.embeds[movieName])
	      return document.embeds[movieName];
  } else {
	  return document.getElementById(movieName);
  }
}

function play_c_player()
{
	if(jQuery.browser.msie) {
		if ($("div[id$='_jwplayerControlbar']").attr('id') != undefined) {
			//jQuery.jwplayer().play();
			if (jQuery.jwplayer().config.autostart !== true) {
				jQuery.jwplayer().play;
				setTimeout(jQuery.jwplayer().play, 3000);
			}
		} else {
			if (jQuery.jwplayer().config.autostart !== true) {
				jQuery.jwplayer().play;
                setTimeout(jQuery.jwplayer().play, 3000);
			}
		}
	} else {
		if (jQuery.jwplayer().config.autostart !== true) {
			jQuery.jwplayer().play;
			setTimeout(jQuery.jwplayer().play, 3000);
		}
	}
}

function move_controls() {
	var pl = $("div[id$='_jwplayer']");
	var cb = $("div[id$='_jwplayerControlbar']");
	if ( (pl.height() != null) && (pl.height() != 'undefined') ) {
		if ( pl.parent().attr("id") != "onPagePlayerBody") {
			pl.css("top","-30px");	
		}
		//for home page	
		var cb_top = parseFloat($(".fpo_video_close").css('top')) + 30;
		//for Experience-Loudoun, Wine-Country and Tours pages
		if ( pl.parent().attr("id") == "onPagePlayerBody" ) {
			cb_top = pl.height() - cb.height() - 50;
		}
		cb_top += "px";
		var cb_wid = parseFloat(cb.css('width')) - 108;
		cb_wid += "px";
		var cb_left = parseFloat(cb.css('left')) + 50;
		cb_left += "px";
		cb.css({
			top: cb_top,
			width: cb_wid,
			left: cb_left
		});
		var time_wid = parseFloat($("div[id$='_timeSliderRail']").css('width')) - 108;
		time_wid += "px";
		$("div[id$='_timeSliderRail']").css('width', time_wid);
		cl_left = parseFloat($("div[id$='_capLeft']").css('left')) - parseFloat($("div[id$='_capLeft']").css('width'));
		cl_left += "px";
		cr_right = parseFloat($("div[id$='_capRight']").css('right')) - parseFloat($("div[id$='_capLeft']").css('width'));
		cr_right += "px";
		$("div[id$='_capLeft']").css('left', cl_left);
		$("div[id$='_capRight']").css('right', cr_right);
	} else {
		setTimeout(move_controls, 200);
	}
}

