/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

window.application = window.application || {};

$(document).ready(function(){
    
    /**base global actions binding **/
     $(".helpWindow, a.addFriend[href], a.removeFriend[href], img.spor").tipTip({
        defaultPosition:"bottom"
        //keepAlive: true
    });
    
    $("form input[type=text].default, form textarea.default , textarea.default").each(function(){  
        this.defaultValue = this.value;
        this.placeholderInit = true;  
	$(this).focusin(function(){    
	    if($(this).hasClass("default")) $(this).removeClass("default");
	    if(jQuery.trim(this.value)==this.defaultValue) this.value =  "";
        })
        $(this).focusout(function(){
	    if(jQuery.trim(this.value)==this.defaultValue || !jQuery.trim(this.value)) {
		    this.value =  this.defaultValue;
		    $(this).addClass("default");
		} 
	 })
    })

    
    
   
    
    
    /**UI for working wut setting tab **/
    var settingcollapsedHeight = $("#appSettings").height();
    $("#appSettings img.hrefLike").click(function(){
        $(this).hide()
        window.setTimeout(function(){ $("#appSettings .cancelButt").click() } ,10);
    })
   $("#appSettings").hover(
    function(){
	if(!this.opende){
	    $(this).css("padding-right","17px")
	}
    },
    function(){
	if(!this.opende){
	    $(this).css("padding-right","10px")
	}
    }
    )

   $("#appSettings .activation").click(function(){
       var cont = $("#appSettings")[0]
      $("#appSettings").animate(
		{width:400,height:250},
		300,
		'linear',
		function(){
		    cont.opende = true
                     $("#appSettings img.hrefLike").show();
                     $("#appSettings").css("overflow","visible");
		}
	     );
   })
   $("#appSettings .cancelButt").click(function(){
         $("#appSettings img.hrefLike").hide();
          $("#appSettings").css("overflow","hidden");
        var cont = $("#appSettings")[0]
      $("#appSettings").animate(
		{width:15,height:settingcollapsedHeight},
		300,
		'linear',
		function(){
		    cont.opende = false
                  $("#appSettings img.hrefLike").hide();
                     $("#appSettings").css("overflow","hidden");
		    $(this).mouseout()
		}
	     );
   })
   /**CHECK TIMEZONE OFFSSET OFF WEB BROWSER AND SEND IT BACK TO SERVER IF REQUESTED**/
   /*IF SERVER DIRECLTY REQUEST offset information */
   if(window._tzOffsetSendAction && $("#lookforTzOffset").length){
       var bDate = new  Date();
       var offset = -1*(bDate.getTimezoneOffset()/60);
       $.post(window._tzOffsetSendAction,{offset:offset},function(data){
           //console.log(data)
       });
   }
   //otherwiese try to compare actual tz offset with values stored in cookies
   //in cse of difference send new offset to server
   else{
       var bDate = new  Date();
       var offset = -1*(bDate.getTimezoneOffset()/60);
       var cookieOffset = parseInt($.cookie('_svt_UTC_tzHOffset'));
       //in case of different betweencookies and actual offset try send actualoffset to server
       if(cookieOffset != offset){
          var address = "/"+window._app_lang+"/Homepage/TimeZoneOffset";
          //console.log(address)
          $.post(address,{offset:offset},function(data){
           //console.log(data)
            });
       }
   }
})


