$(document).ready(function(){
	$().mousemove(function(event){
				var target = $(event.target);
				
				window.cursorPosX = event.pageX;
				window.cursorPosY = event.pageY;
				
				if($('#cursorSatellite').length > 0){
					$('#cursorSatellite').css('top', window.cursorPosY);
					$('#cursorSatellite').css('left', window.cursorPosX+15);	
				}
				
				if(SmWinCurElem != null && !target.parents().is('.UCmenu') && SmWinPermanent != true){
					closeSmWin();
				}
				
				if(curDashMenuEl != 'undefined' && !target.parents().is('.dashMenu')){
					closeDashMenu(curDashMenuEl);
				}
				
				if(Dashmenu.oel && !target.hasClass('.dashItem') && !target.parents().is('.dashItem')) {
					Dashmenu.close();
				}
    });
            
	$(document).click(function(event) {
						var target = $(event.target);
					    //close SwWin if opened
					    if(SmWinCurElem != null && !target.is("#SmWin") && !target.parents().is('#SmWin')){
							closeSmWin();
					    } 
						
						if(window.uisel != 'undefined' && !target.parents().is('.UISelecter')){
							$('#privacyLevels').slideUp('fast');
							window.uisel = 'undefined';
						}

						if(window.uiselect != 'undefined' && !target.parents().is('.ui-select')){
							$('.ui-select #ui-select-list').slideUp('fast');
							window.uiselect = 'undefined';
						}
						
						if(!target.parents().is('.dropDown')) {
							$('.dropDown.active').removeClass('active');
						}
					});
	
	$('.ui-select #ui-select-toggler').bind('click', function(event) {
		var target = $(event.target);
		target.parent().find('#ui-select-list').slideToggle('fast');
		window.uiselect = true;
	});
	$('.ui-select #ui-select-list a').bind('click', function(event) {
		var target = $(event.target);
		var uiSelect=target.parents('div').closest('.ui-select');
		var onchangeCallback=uiSelect.attr('onchangeCallback');
		uiSelect.find('#ui-select-toggler').html(target.html());
		uiSelect.find('#ui-select-list a').removeClass('selected');
		target.addClass('selected');
		var value=target.attr('rel');
		uiSelect.find('input').val(value);
		uiSelect.find('#ui-select-list').slideUp('fast');
		window.uiselect = true;
		if (onchangeCallback) {
			eval(onchangeCallback);
		}		
	});		
	if ( $(".ui-select").length > 0 ) {
		$(".ui-select").each(function(){
			var uiSelect=$(this);
			var selected=uiSelect.find('.selected:first');
			if (selected.length > 0) {
				uiSelect.find('#ui-select-toggler').html(selected.html());
				var value=selected.attr('rel');
				uiSelect.find('input').val(value);	
			}
			else {
				/*
				selected=uiSelect.find('a:first');
				uiSelect.find('#ui-select-toggler').html(selected.html());
				var value=selected.attr('rel');
				uiSelect.find('input').val(value);
				*/				
			}			
		});	
	}	

	var pageCounter=getCookie('pageCounter');
	if (pageCounter == null) pageCounter=0;
	if(LOGGED==0){
		var timeWill=new Date;
		var newHours=timeWill.getHours()+12;
		timeWill.setHours(newHours);
		var expires=timeWill.toUTCString();
		if(pageCounter>0){
			var showAjaxTour=null;
			showAjaxTour=getCookie('showAjaxTour');
			if(showAjaxTour==null){
				setCookie('showAjaxTour','1',expires,'/');
				_gaq.push(['_trackPageview','/virtual/pop-up-unregistered']);
				Window.load('/ajax/tourMod', 'win_tour', '');
				}
			}
	}
	
	if (pageCounter == 0){
		var foo = new Date; // Generic JS date object
		var unixtime_ms = foo.getTime(); // Returns milliseconds since the epoch
		var unixtime = parseInt(unixtime_ms / 1000);
		setCookie('firstTime',unixtime,expires,'/');
	}
	
	pageCounter=parseInt(pageCounter)+1;
	setCookie('pageCounter',pageCounter,expires,'/');
});

$(window).bind("load",function(){
	if($.isFunction(window.resizeCommentImages))
	{
		window.resizeCommentImages();
	}			   
});

	$('a.photo_s').lightBox(lightBoxOptions);

	/*$("#mainContent").ready(function(){
		hasher(true);				   
	});
	
	$(window).bind('hashchange', function() {
		hasher();
	});*/
	

	window.onpopstate = function (event) {
		  if (event.state) {
			  location.href=document.location;
		  } else {
		    // history changed because of a page load
		  }
		}	
	
	$(document).keyup(function(e) {
	  if(e.keyCode == 37 && e.ctrlKey ) { // left
	    $('#mainContent .navArrowL, #mainContent .photoArrowL').trigger('click');
	  }
	  else if(e.keyCode == 39 && e.ctrlKey) { // right
	    $('#mainContent .navArrowR, #mainContent .photoArrowR').trigger('click');
	  }
	});	
