$(document).ready(function() {
	
	/* 
	
	font.setup();
	if (font.isInstalled("Calibri")) ImportCss("calibri.css"); 
	
	function ImportCss(name) {
		if (document.createStyleSheet) {
			document.createStyleSheet('/css/' + name);
		}
		else {
			var styles = '/css/' + name;
			var newSS = document.createElement('link');
			newSS.rel = 'stylesheet';
			newSS.type = 'text/css';
			newSS.href = styles;
			document.getElementsByTagName("head")[0].appendChild(newSS);
		}
	}
	
	$('.navSubscribe').mouseover(function(){
		$('#subscribeOverlay').show();
	})
	
	$('.navSubscribe').mouseout(function(){
		if ($('#subscribeEmail').hasClass('focusField')){  
        } 
		else {
			$('#subscribeOverlay').hide();
		}
	})
	
	$('#subscribeEmail').blur(function(){
	  $('#subscribeOverlay').hide();
	});
	
	*/
	
	$('a[href^="http://"]').attr("target", "_blank");
	
	imageGalleryPages = $(".detailGallery #gallery > img").size();
	videoGalleryPages = $(".detailGallery #videoGallery > div").size();
	currentPage = 1;
	
	$("#galleryControls span.pageNumber").html(currentPage + ' of ' + imageGalleryPages);

	$("#galleryControls .next").click(function() {
		if (currentPage == imageGalleryPages){
			currentPage = 1;
			$("#galleryControls span.pageNumber").html(currentPage + ' of ' + imageGalleryPages);
		} else {
			currentPage = currentPage + 1;
			$("#galleryControls span.pageNumber").html(currentPage + ' of ' + imageGalleryPages);
		}
	});
	
	$("#galleryControls .previous").click(function() {
		if (currentPage == 1){
			currentPage = imageGalleryPages;
			$("#galleryControls span.pageNumber").html(currentPage + ' of ' + imageGalleryPages);
		} else {
			currentPage = currentPage - 1;
			$("#galleryControls span.pageNumber").html(currentPage + ' of ' + imageGalleryPages);
		}
	});
	
	
	$('input[type="text"]').focus(function() {  
        $(this).addClass("focusField");  
        if (this.value == this.defaultValue){               
			this.value = '';  
         }  
        if(this.value != this.defaultValue){  
            this.select();  
        }  
     }); 
	
	$('input[type="text"]').blur(function() {  
        $(this).removeClass("focusField");  
        if ($.trim(this.value) == ''){  
             this.value = (this.defaultValue ? this.defaultValue : '');  
        }  
     });  
	
	$('.rateThis .rating li').click(function(){
		$('.rateThis .rating li').removeClass('active');
		$('.rateThis .rating li').removeClass('hover');
		$(this).addClass('active');
		$(this).prevAll().addClass('active')
	})
	
	$('.rateThis .rating li').mouseover(function(){
		$('.rateThis .rating li').removeClass('hover');
		$(this).addClass('hover');
		$(this).prevAll().addClass('hover')
	})
	
	$('.rateThis .rating li').mouseout(function(){
		$('.rateThis .rating li').removeClass('hover');
	})
	
	$('.detailGallery .buttonBrown a').click(function(){
		$('.detailGallery .rateThis').toggle()
	})
	
	$('#priceLegendContainer .priceLegendLink').click(function(){
		$('#priceLegend').toggle();
	})
	
	$('.videoThumbs li').click(function(){
		$('.videoThumbs li').removeClass('active');
		$('.videoPlayer img').removeClass('active');
		$(this).addClass('active')																			
	})
	
	$('.videoThumbs .video1').click(function(){  $('.videoPlayer .video1').addClass('active'); })
	$('.videoThumbs .video2').click(function(){  $('.videoPlayer .video2').addClass('active'); })
	$('.videoThumbs .video3').click(function(){  $('.videoPlayer .video3').addClass('active'); })
	$('.videoThumbs .video4').click(function(){  $('.videoPlayer .video4').addClass('active'); })
	
	$('.cityGuides img.arrow').click(function(){
		$('.cityGuides').toggleClass('dropdown');
		$('.cityGuides .level02').toggle()
	})
	
	$('.cityGuides .level02 li').click(function(){
		$('.cityGuides .level02 li').removeClass('active');
		$('.cityGuides .level03').hide();
		$(this).addClass('active');
		$(this).find('.level03').toggle()
	})
	
	var level02Config = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 0, // number = milliseconds for onMouseOver polling interval    
     over: function () {}, // function = onMouseOver callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onMouseOut    
     out: function () {
		$('.cityGuides').removeClass('dropdown');
		$('.level02 li').removeClass('active');
		$('.level02 .level03').hide();
        $(this).hide();
      } // function = onMouseOut callback (REQUIRED)    
	};
	
	var level03Config = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 0, // number = milliseconds for onMouseOver polling interval    
     over: function () {}, // function = onMouseOver callback (REQUIRED)    
     timeout: 1000, // number = milliseconds delay before onMouseOut    
     out: function () {
		$('.level02 li').removeClass('active');
        $(this).hide();
      } // function = onMouseOut callback (REQUIRED)    
	};
	
	$(".cityGuides .level02").hoverIntent( level02Config )
	$(".cityGuides .level03").hoverIntent( level03Config )	 

    $("#rateThisButton").click(function() {
		var rating = 0;
		if ($("#selectedRating li:eq(0)").attr("class") == "active")
			rating = 1;
		if ($("#selectedRating li:eq(1)").attr("class") == "active")
			rating = 2;
		if ($("#selectedRating li:eq(2)").attr("class") == "active")
			rating = 3;
		if ($("#selectedRating li:eq(3)").attr("class") == "active")
			rating = 4;
		if ($("#selectedRating li:eq(4)").attr("class") == "active")
			rating = 5;
        
        $.ajax({
            type: "POST",
            cache: true,
            url: "/RedvisitorAjax.aspx/AddRating",
            data: "{contentIdValue:'" +  $("#contentID").val() + "',ratingValue:'" + rating + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(data)
            {
                $(".rateThis").hide();
            	$("#userRatingTag").hide("slow", function() {
		        	$("#userRatingTag").empty();
		        	$("#userRatingTag").append("<span class=\"rating" + data + "\">" + data + " out of 5</span>");
		        	$("#userRatingTag").show("slow");
		        });
            }
        });
	});

    $(".readmore a").click(function() {
        $(this).css('visibility', 'hidden');
            $('.moreText').slideDown('slow', function() {
            // Animation complete.
        });
    });
    
});

