$(document).ready(function(){

   $(".news_middle").fadeIn(2000);
   $(".news_tn_pic img").css("opacity","0.3");
   $(".scrollableArea img").css("opacity","0.3");

   $(".news_tn_pic img").mouseover(function(r){
      $(this).animate({ opacity : "1.0"},{duration : "slow", easing :  "easeOutQuart" });
    }).mouseout(function(r){
      $(this).animate({ opacity : "0.3"},{duration : "slow", easing :  "easeOutQuart" });
    });
    
    $(".scrollableArea img").mouseover(function(r){
      $(this).animate({ opacity : "1.0"},{duration : "slow", easing :  "easeOutQuart" });
    }).mouseout(function(r){
      $(this).animate({ opacity : "0.3"},{duration : "slow", easing :  "easeOutQuart" });
    });
    
    $(".right_pager").mouseover(function(r){
      $(".right_pager img").animate({ opacity : "1.0"},{duration : "slow", easing :  "easeOutQuart" });
    }).mouseout(function(r){
      $(".right_pager img").animate({ opacity : "0.1"},{duration : "slow", easing :  "easeOutQuart" });
    });
    $(".left_pager").mouseover(function(r){
      $(".left_pager img").animate({ opacity : "1.0"},{duration : "slow", easing :  "easeOutQuart" });
    }).mouseout(function(r){
      $(".left_pager img").animate({ opacity : "0.1"},{duration : "slow", easing :  "easeOutQuart" });
    });

    $(".news_tn_pic img").click(function(r){
        var id_curr = $(this).attr("img_id");
        var t = this;
        var htmll = "";
        var cur = $("#curr_news").val();
        
        htmll = getIMG(cur,id_curr);

        $(this).parent().prev().html(htmll);
        
        $('#n_'+cur+' .news_right .news_main_pic a').lightBox({fixedNavigation:false});
    });
    
    var global_this = "";
    
    $(".one_work_style_name").mouseover(function(r){
        if(global_this != $(this) && $(global_this).attr("is_active") !=1){
            $(global_this).next().fadeOut("slow");
        }
        global_this = $(this);
        $(this).next().fadeIn("slow"); 
    });
    /*$(".one_word_stlye").mouseout(function(r){
        var thiss = $(this);
        $(".one_work_style_pager", thiss).fadeOut("slow");
    });*/
    
    /*$(".one_work_style_pager").mouseup(function(r){
        $(this).show();
    });*/
    
    $(".img_click").click(function(r){
        var i_id = $(this).attr("img_id");
        
        $("#sqr_"+i_id).css("background-color","#000000");
       //alert("a"); 
    });
    
    $(".img_click").mouseover(function(r){
        var i_id = $(this).attr("img_id");
        $("#sqr_"+i_id).css("background-color","#000000");
    }).mouseout(function(r){
        $(".one_square").each(function(r){
               $(this).css("background-color","#626262"); 
            });
    });

    $(".menu_texts_no a").hover(function() {
        $(this).animate({ color: "#000000" }, { duration :500});
            },function() {
                $(this).animate({ color: "#626262" }, { duration :500});
    });
    
    $(".one_work_style_pager a").hover(function() {
        $(this).animate({ color: "#000000" }, { duration :500});
            },function() {
                $(this).animate({ color: "#626262" }, { duration :500});
    });
        
    $(".one_work_style_name").mouseover(function(r){
        $(this).animate({ color: "#000000" }, { duration :500});
    }).mouseout(function(r){
        $(this).animate({ color: "#626262" }, { duration :500});
    });
    
    $(".next_news").click(function(r){
        var cur = $("#curr_news").val();
        var total = $("#total_news").val();
        
        cur++;
        if(cur > total ){
            moveTo(total);
        } else {
            moveTo(cur);
        }
        displayControll(cur,total)
    });
    
    $(".prev_news").click(function(r){
        var cur = $("#curr_news").val();
        var total = $("#total_news").val();
        
       cur--;
       if(cur < 1 ){
            moveTo(1);
       } else {
            moveTo(cur);
       }
       displayControll(cur,total);
    });

});


var ttt;
function menuAnim(){
    $(".menu_con").show();
    menuPlay();
}

function menuPlay(){
        $('div.pinetree').pngFix( );
        $(".pinetree").animate(
        {marginTop: '39px'}, {
        duration : 2000 , 
        easing : "easeOutCubic" ,
        complete : function(){
                    $(".szalaypeti").show();
                    $('div.szalaypeti').pngFix( );
                    $(".szalaypeti").animate(
                        {marginLeft: "0px"},{
                        duration : 3700 ,
                        easing :  "easeOutQuint",
                        complete: function(){
                                    $(".link").each(function(i) {
                                        /*$(this).css("opacity","0.0");*/
                                        $(this).delay(i*400).animate(
                                            {marginTop: "0px"},{
                                            duration : 1700,
                                            easing : "easeOutQuint",
                                            complete : function(){
                                                    if(i == 3){
                                                        window.open("?module=news","_self");
                                                    }
                                                }
                                            }
                                        );                        
                                    });
                                }
                        }
                    );
                }
        }
    );
}

function checkControllers(){
    
    var cur = $("#curr_news").val();
    var tot = $("#total_news").val();
    
    displayControll(cur,tot);
    //$(".white_part").delay(1000).fadeIn(2000);
}

function displayControll(cur,tot){
    if(cur > 1){
        $(".prev_news").fadeIn("slow");
    } else {
        $(".prev_news").hide();
    }
    
    if(cur != tot){
        $(".next_news").fadeIn("slow");
    } else {
        $(".next_news").hide();
    }
    
    
}

function moveTo(prev){
    var distance = 730;
    var step = (1 - prev) * -1;
    var step_dis = step * distance;
        
    $(".news_con").animate({left:"-"+step_dis+'px'}, {duration : 2000, easing : "easeOutQuart"});
    $("#curr_news").val(prev);
}

function getIMG(cur, id_curr){
    var htmll = "";
    var str = "#n_"+cur+" .news_right .news_tn_pic img";
    var a = "";
    $(str).each(function(i) {
        var this_id = $(this).attr("img_id");
        //alert(id_curr+" - "+this_id);
        if(id_curr == this_id){
            a = "";
            a = '<a href="user_pic/'+this_id+'_big.jpg"><img src="user_pic/'+this_id+'.jpg" /></a>';
            htmll += a;
        } else {
            a = "";
            a += '<a style="display:none;" href="user_pic/'+this_id+'_big.jpg"><img src="user_pic/'+this_id+'.jpg" /></a>';
            htmll +=a;
        }
    } );
    return htmll;
}