    
    
   $(document).ready(function(){
       // authorization
            $('.e_signup').click(function(){                 
                var callback = function(){ document.location.href = LANG+'/comments'; }
                $(document).trigger('popup', [600, 450, 'hc_auth', 'http://' + (document.location.hostname.indexOf('dev.') == -1 ? 'hypercomments.com' : 'dev.hypercomments.com') + '/auth/index?service=google', callback]);
            });  
            
            // get to prising page
            $('.e_prising').click(function(){ document.location.href = LANG+'/pricing'; });
            
            // open livehelp siteheart window
            $('.e_livehelp').click(function(){ $(document).trigger('popup', [550, 450, 'hc_livehelp', 'https://siteheart.com/chat/338850?s=1']); });
//            
            
            $('.e_me').click(function(){
                 document.location.href = LANG+'/comments';
            });
            
            $('.e_login').click(function(){
                document.location.href = LANG+'/install';
            });
            
            $('.e_to_features').click(function(){
                document.location.href = LANG+'/features';
            });
            
            $('.e_to_sandbox').click(function(){
                document.location.href = LANG+'/site/page/alias/sandbox';
            });
           
            
            $('.e_logout').click(function(){
               
                $.post('/auth/logout', function(){
                    Delete_Cookie('es','/','.hypercomments.com');
                    document.location.href = '/site/logout';})
            });
//                     
//           
           $('.e_pricing').click(function(){
               var tarif = $(this).data('tarif');
//               if(ACC){
//                   document.location.href = LANG+'/pricing/create?tarif='+tarif;
//               }else{
                    var callback = function(){ document.location.href = LANG+'/pricing/create?tarif='+tarif; }
                    $(document).trigger('popup', [600, 450, 'hc_auth', 'http://' + (document.location.hostname.indexOf('dev.') == -1 ? 'hypercomments.com' : 'dev.hypercomments.com') + '/auth/index?service=google', callback]);
//               }
           });
           
           $('.e_change_tarif').click(function(){
               var tarif = $(this).data('tarif');
               if(tarif == 'free'){                  
                    if (confirm('Are you sure?')) {
                        $.post('/finance/cancel',{},function(data){
                            var data = $.parseJSON(data);
                            if(data.result == 'success'){
                                $('#responce').addClass('message_success').show().text(data.description);
                                setTimeout(function(){
                                    document.location.reload();
                                }, 4000);
                            }else if(data.result == 'redirect'){
                                document.location.href = LANG+'/pricing/create?tarif=free';
                            }else{
                                $('#responce').addClass('message_error').show().text(data.description);
                            }
                        });
                    }              
               }else{
                   document.location.href = LANG+'/payment/create?plan='+tarif;
               }
               
           });
//           
           $('.e_lang a').click(function(){
               var lang = $(this).data('lang');                                
               Delete_Cookie('lang','/','.hypercomments.com');
               setCookie('lang',lang);
               
           });
           
           function setCookie(c_name,value,exdays)
           {
               var exdate=new Date();
               exdate.setDate(exdate.getDate() + exdays);
               var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
               document.cookie=c_name + "=" + c_value;
           }
//            
            function Get_Cookie( name ) {
                var start = document.cookie.indexOf( name + "=" );
                var len = start + name.length + 1;
                if ( ( !start ) &&
                ( name != document.cookie.substring( 0, name.length ) ) )
                {
                    return null;
                }
                if ( start == -1 ) return null;
                var end = document.cookie.indexOf( ";", len );
                if ( end == -1 ) end = document.cookie.length;
                return unescape( document.cookie.substring( len, end ) );
            }
            
            function Delete_Cookie( name, path, domain ) {
            if ( Get_Cookie( name ) ) document.cookie = name + "=" +
            ( ( path ) ? ";path=" + path : "") +
            ( ( domain ) ? ";domain=" + domain : "" ) +
            ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
            }
       
   });                    
            
    
   
    // Open PopUp window
    $(document).bind('popup', function(e, width, height, name, url, callback){
        
	var x = (640 - width)/2;
	var y = (480 - height)/2;			
	if (screen) {
	    y = (screen.availHeight - height)/2;
	    x = (screen.availWidth - width)/2;
	}
        var w = window.open(url, name , "menubar=0,location=0,toolbar=0,directories=0,scrollbars=0,status=0,resizable=0,width=" + width + ",height=" + height + ',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	    w.focus();
			    
	    if(callback)
	    var interval = setInterval(function(){
	    if (!w || w.closed){
	  	clearInterval(interval);
	  	callback();
	    }
	    }, 500);
         	   
    });
	
	
	var SLIDE_TIME = 10000;
	var SLIDE_TIMER;
	$(document).bind('slide', function(e, back){
		
		var slide = $('.hiper_com_slide:visible');
		var width = slide.width();
		
		var onSuccess = function(){
			slide.hide();
			//if($('.hiper_com_slide:first').is(':visible')){
			//	$('.hc_bt_list_back').hide();
			//	$('.ic_list_arrow').show();
			//}else if($('.hiper_com_slide:last').is(':visible')){
			//	$('.hc_bt_list_back').show();
			//	$('.ic_list_arrow').hide();
			//}else{
				//$('.hc_bt_list_back').show();
				//$('.ic_list_arrow').show();
			//}
		}
		
		if(!back){
			var next  = slide.next('.hiper_com_slide');		
			if(!next.size())
				next= $('.hiper_com_slide:first');
			next.css({left : width, position : 'absolute'}).show();			
			slide.css({position : 'absolute'});
				
			slide.animate({left : -width}, onSuccess);
			next.animate({left : 0});
		}else{
			var prev  = slide.prev('.hiper_com_slide');		
			if(!prev.size())
				prev= $('.hiper_com_slide:last');
			prev.css({left : -width, position : 'absolute'}).show();			
			slide.css({position : 'absolute'});
				
			slide.animate({left : width}, onSuccess);
			prev.animate({left : 0});
		}
		
		SLIDE_TIMER = setTimeout(function(){ $(document).trigger('slide');}, SLIDE_TIME);
		
	});
    
    
    $(function(){
	
		$('.hc_bt_list_back').show();
		$('.ic_list_arrow').show();
		
		$('.hc_bt_list').bind('click', function(){
			if(SLIDE_TIMER)clearTimeout(SLIDE_TIMER);
			$(document).trigger('slide');
		});
		
		$('.hc_bt_list_back').bind('click', function(){
			if(SLIDE_TIMER)clearTimeout(SLIDE_TIMER);
			$(document).trigger('slide', [true]);
		});
		
		SLIDE_TIMER = setTimeout(function(){ $(document).trigger('slide');}, SLIDE_TIME);
	
	});
    
    
    
