﻿$(document).ready(function(){

if($('#screen').length > 0){	
$('#screen').cycle({
	fx:    'fade',
	speed: 1300,
	timeout:  6000,	 
    pause:  0,
    next:   '.p_img'	 
});
$("#big_player > #screen > .player_img").bind("mouseenter", function(e){
        $(this).children(".player_text").animate({"top": '403px'}, "slow");
    });
$("#big_player > #screen > .player_img").bind("mouseleave", function(e){
        $(this).children(".player_text").animate({"top": '433px'}, "slow");
    });

$("#small_player > #screen > .player_img").bind("mouseenter", function(e){
        $(this).children(".player_text").animate({"top": '240px'}, "slow");
    });
$("#small_player > #screen > .player_img").bind("mouseleave", function(e){
        $(this).children(".player_text").animate({"top": '270px'}, "slow");
    });
}

if($('#post_line').length > 0){	
$('#post_line').cycle({
	fx:    'scrollUp',
	speed: 1300,
	timeout:  4000,	 
    pause:  0,
    cleartype:     true,
    cleartypeNoBg: true	
});        
}
});

function player_pause(){
	$('#screen').cycle('pause');
	$(".player_button").attr({ 
          href: "javascript: player_resume();",
          title: "возобновить"
        });
      $(".player_button").addClass("resume_button");
     
     
}
function player_resume(){
	$('#screen').cycle('resume');
	$(".player_button").attr({ 
          href: "javascript: player_pause();",
          title: "пауза"
        });
     $(".player_button").removeClass("resume_button");    
}

function show_form_subscribe(){
if($("#float_window").length > 0){
	$("#float_window").remove();
	}
	else{
	$("<div id=\"float_window\" style=\"display:none\">").appendTo("body");	
	$("#float_window").load("/ajax/show_form_subscribe",   
  				function(resp){
  					$("#float_container").css({top: '192px', margin: '0px -200px'});
  					$("#float_window").animate({opacity: 'show'}, 100);
  					$("#email").bind("blur", function(){
  						var reg = /[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/i;
  						var email = $(this).val();
  						if(reg.test(email)){
  							$('#subbutton').removeAttr("disabled");
  							
  							$.post("/ajax/check_subscribe", { mail: email}, 
   									function(data){
   										if(data.subs==true){
      										$("#subscribed").html('you, our subscribers');
      										$("#user_name").val(data.user['name']);
      										$("form :checkbox").each(function(){
        										if(data.user[$(this).attr("name")] == 1){
        										 $(this).attr("checked","checked");
        										}
      											});
   										}
     								}, "json");
  						}
  						else{
  						 alert('Input valid E-mail!');
  						 $("#email").focus();
  						}
					});
  				});
	}
}
function add_subscribe(){
	var fields = $("form :input").serializeArray();
	$.post("/ajax/add_subscribe", fields, 
   		function(data){
   			alert(data.mess);
   			show_form_subscribe();
   		}, "json");	
}  
