(function($){var pageTracker;$.geekGaTrackPage=function(account_id){var host=(("https:"==document.location.protocol)?"https://ssl.":"http://www.");var src=host+'google-analytics.com/ga.js';$.ajax({type:'GET',url:src,success:function(){pageTracker=_gat._getTracker(account_id);pageTracker._trackPageview();},error:function(){throw"Unable to load ga.js; _gat has not been defined.";},dataType:'script',cache:true});};
$.geekGaTrackEvent=function(category,action,label,value){if(typeof pageTracker!=undefined){pageTracker._trackEvent(category,action,label,value);}else{throw"Unable to track event; pageTracker has not been defined";}};})(jQuery);
var $loading = $('#loading');
var $iconnav = $('#iconnav');
function populate_country() {
    $.getJSON('/v2/ajax/fetch_resort.php', {country:$('#country').val()}, function(data) {
        var select = $('#resorts');
        var options = select.attr('options');
        $('option', select).remove();
        $.each(data, function(index, array) {
        options[options.length] = new Option(array['resort']);
        });
    });
}

$(document).ready(function() {   
$('.swap, #currentswitch, #activecam, #xcams, #advertise, #newurl, #suggest').hide(); 
$iconnav.hide();

populate_country();
$('#country').change(function() {
	populate_country();
});
	   
$("#sbmt").click(function() {
var ajaxOpts = {
type: "post",
url: "/v2/ajax/comment.php",
data: "&author=" + $("#xtransbox2").find("input#author").val() + "&msg=" + $("#xtransbox2").find("textarea").val() + "&city=" + $("#xtransbox2").find("input#city").val() + "&cam_id=" + $("#xtransbox2").find("input#cam_id").val() ,
success: function(data) {
  var div = $("<div>").addClass("bxbox").prependTo("#xlist");
  $("<div>").addClass("author").text($("#xtransbox2").find("input#author").val()).appendTo(div);
  $("<p>").addClass("yourcomment").text($("#xtransbox2").find("textarea").val()).appendTo(div);
  $('#xtransbox2').hide();
}
};
$.ajax(ajaxOpts);
});

$("#resorts").change(function(){	 
document.location.href = '/webcams/' + $(this).children("option:selected").attr("value");
});
   
	$('#activecam').fadeTo(200,1,function(){
	$('#activecam').fadeIn("slow");
	$('.swap').show(); 
	});
	
	$('#xcams').fadeTo(500,1,function(){
    $('#xcams').fadeIn("slow");
  	});
  	
  	$iconnav.fadeTo(1000,1,function(){
    $iconnav.fadeIn("slow");
  	});
  	
  	$('#advertise').fadeTo(1500,1,function(){
    $('#advertise').fadeIn("slow");
  	});
  	
  	$(".unit-rating").css({opacity: 0.9});
  	
 $('img.captify').captify({
		speedOver: 'fast',
		speedOut: 'normal',
		hideDelay: 800,	
		animation: 'slide',		
		prefix: ' ',		
		opacity: '0.6',					
		className: 'caption-bottom',	
		position: 'bottom',
		spanWidth: '100%'
 });
	
    $("#search #ac_me").autocomplete("/v2/inc/suche.php", { minChars:4, matchSubset:1, matchContains:1, cacheLength:10, onItemSelect:navigation, formatItem:formatItem, selectOnly:1 });
    
     $("a.thumb img").error(function () {
     $(this).parent().parent().hide("fast");
     pos3 = $(this).attr("id"); 
     reportrefcam();
     });
          
    function reportrefcam()
	{
	$.post("/v2/ajax/report.php", { id: pos3},
	function(data10){
    });	
	}
      
	$("#open").click(function(){
		$("div#panel").slideDown("slow");	
	});	
	
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});		
	
     $("ul.showcase .thumb img").lazyload({placeholder : "/v2/gfx/blank.gif", effect : "fadeIn"});
                 
	 $(".addcat").hover(function() {
     $(this).css('cursor', 'crosshair');
     });	  
      	       
     $("#msg").click(function() {
	 $('#ready').show('slow');	
	 });
      	  
	 $iconnav.fadeTo("slow", 0.5);
	 $iconnav.hover(function(){
	 $iconnav.fadeTo("slow", 1.0); 
	 },function(){
	 $iconnav.fadeTo("slow", 0.5); 
	 });      

	 $('#thanks').fadeTo(10000,1,function(){
     $('#thanks').hide("slow");
  	 });
  
  $(".swap span").hover(function() {
$(this).css('color', '#fff');

}, function() {
$(this).css('color', '#9cb0c9');

return false; 
});

$("textarea").hover(function() {
$(this).css('color', '#FEDE65');
$(this).css('border-color', '#27303F');
}, function() {
$(this).css('color', '#CFB55A');
$(this).css('border-color', '#1D242F');
});
        
$('#search input[type="text"]').focus(function() {
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
});
$('#search input[type="text"]').blur(function() {
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
});
    		
});

$(window).load(function(){
$.geekGaTrackPage('UA-1808769-1');		
});	

 function navigation(li)
       {
       if (li.extra)
       {
               location.href = "/webcams/" + li.extra[0];
       }
       }

        $().ajaxStart(function() { 
        $loading.show(); 
        });
        
        $().ajaxStop(function() {
        $loading.hide("fast");
        });
        

jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	
	return this;
};

function selectItem(li) {
	if (li.extra) {
	return "<a href='/webcams/" + row[0] + "'>" + row[1] + "</a>";
	}
}

function formatItem(row) {
	return "<a href='/webcams/" + row[0] + "'>" + row[1] + "</a>";
}      