(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');

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() {   

populate_country();
	$('#country').change(function() {
		populate_country();
	});
	
$("#resorts").change(function(){	 
document.location.href = '/webcams/' + $(this).children("option:selected").attr("value");
});
    
    var $iconnav = $('#iconnav');
      	  
    $('.swap, #advertise, #currentswitch, #ubb').hide(); 
    $iconnav.hide();
       
	$('#activecam').fadeTo(600,1,function(){
	$('#activecam').fadeIn("slow");
	$('.swap').show(); 
	});
	$('#xcams').fadeTo(900,1,function(){
    $('#xcams').fadeIn("slow");
  	});
  	
  	$iconnav.fadeTo(1100,1,function(){
    $iconnav.fadeIn("slow");
    
    $('#advertise').fadeTo(1400,1,function(){
	$('#advertise').fadeIn("slow");
	});
	
  	});
  	
  	$(".unit-rating").css({opacity: 0.8});
  	
 $('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");
  	 });
         
        $("input, select").hover(function() {
        $(this).css('color', '#af9e99');
        $(this).css('border-color', '#3F3837');
		}, function() {
    	$(this).css('color', '#6f6461');
    	$(this).css('border-color', '#211A18');
        });
        
        $("textarea").hover(function() {
        $(this).css('color', '#FEDE65');
        $(this).css('border-color', '#3F3837');
		}, function() {
    	$(this).css('color', '#CFB55A');
    	$(this).css('border-color', '#211A18');
        });
        
        jQuery('select').live('focusin', function(){
	$(this).css('color', '#af9e99');
	$(this).css('border-color', '#3F3837');
	});
	jQuery('select').live('focusout', function(){
	$(this).css('color', '#6f6461');
	$(this).css('border-color', '#211A18');
	});

         
        	$('#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 : '');
				}
    		});
    		
         //$(document).bind("contextmenu",function(e){
	     //return false;
         //});

     });
        
        
$(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>";
}        		
     

   