$(".first").ready(function()
{
    if($.cookie("first_visit") == "true")
    {    
        $(".first").hide(0);
        $(".last").fadeIn(0);
    }
});
$(function()
{                
    $(".first, .last").css("height",$(document).height() + "px");
    if($.cookie("first_visit") != "true")
    {    
        setTimeout(function()
        {            
            $(".first").fadeOut(1500, function()
                {
                    $(".last").fadeIn(500);
                    $(".gray").each(function()
                    {        
                        var obj = this;        
                        setTimeout(function()
                        {
                            Pixastic.process(obj, "desaturate");
                        }, 1000);                       
                    });                 
                });
        }, 1500);
        var date = new Date();
        date.setTime(date.getTime() + (15 * 60 * 1000));
        $.cookie("first_visit", "true", 
        {
            expires: date
        });    
    }       
    $(".menu a").bind("mouseover", function()
    {
        var color = $(this).attr("color");
        var addition;
        $(".menu a").each(function(index)
        {
            if(color == $(this).attr("color"))
            {
                addition = index;
                return false;
            }    
        });
        $(".slider").stop()
            .css("background-color", "#" + color).fadeTo(0, 0.5);
        var width = $(this).width();
        var height = 36;
        var top = $(this).parent().position().top;// + addition; 
        //$(".menu").position().top + 36 * addition + 80;         
        var left = $(this).position().left;
        var padding = 21;
        width += padding * 2;        
        $(".slider").height(height)
            .css({"top": top, "left": left - padding})        
            .animate({width: width + "px"});
    });  
    $(".menu a").bind("mouseout", function()
    {
        $(".slider").stop();
        $(".slider").height(0).width(0);                    
    }); 
    $(".gray").each(function()
    {        
        var obj = this;        
        setTimeout(function()
        {
            Pixastic.process(obj, "desaturate");
        }, 1000);                       
    });        
    var from = 0;
    var to = 5;     
    var srcPrev;
    var srcNext;        
    $("#next").bind("click", function()
    {                
        if(from + 6 < $(".item").length)
        {            
            from += 6;
            to += 6;
            show(from, to);           
            $("#prev img").attr("src", "templates/default/images/link-left-active.png");        
        }                                 
        if(to > $(".item").length)
        {
            srcNext = "templates/default/images/link-right.png";
            $(this).find("img").attr("src", "templates/default/images/link-right.png");             
        }        
    });  
    $("#prev").bind("click", function()
    {        
        if(from > 5)
        {
            from -= 6;
            to -= 6;
            show(from, to);            
        } 
        if(to < $(".item").length)
        {
            srcNext = "templates/default/images/link-right-active.png";            
            $("#next img").attr("src", "templates/default/images/link-right-active.png");             
        }         
        if(from == 0)
        {
            srcPrev = "templates/default/images/link-left.png";
            $(this).find("img").attr("src", "templates/default/images/link-left.png");
        }       
        else
        {
            $(this).find("img").attr("src", "templates/default/images/link-left-active.png");
        }
    });    
    $("#prev").bind("mouseover", function()
    {
        srcPrev = $(this).find("img").attr("src");
        if(srcPrev != "templates/default/images/link-left.png")
            $(this).find("img").attr("src", "templates/default/images/link-left-hover.png");            
    });
    $("#next").bind("mouseover", function()
    {
        srcNext = $(this).find("img").attr("src");
        if(srcNext != "templates/default/images/link-right.png")
        {
            $(this).find("img").attr("src", "templates/default/images/link-right-hover.png");
        }            
    }); 
    $("#prev").bind("mouseout", function()
    {
        $(this).find("img").attr("src", srcPrev);                    
    });
    $("#next").bind("mouseout", function()
    {
        $(this).find("img").attr("src", srcNext);                   
    });  
    $(".item-color").fadeTo(0, 0.5);  
    $(".item-color").bind("mouseover", function()
    {                          
        $(this).stop()
            .fadeTo(500, 1); 
        $(".navigation-text div")                                    
            .html($(this).parent().find("div.hidden").html())
            .stop()
            .height(0)
            .animate({height: "90px"});
        $(this).parent().find(".gray").each(function()
        {
            Pixastic.revert(this);    
        });      
    }); 
    $(".item-color").bind("mouseout", function()
    {        
        $(this).stop()
            .fadeTo(500, 0.5);
        $(".navigation-text div")
            .stop()
            .height(0)                       
            .html("");
        $(this).parent().find(".gray").each(function()
        {
            Pixastic.process(this, "desaturate");   
        });                                                 
    });  
    $(".gray").live("mouseover", function()
    {
        $(this).parent().parent().parent().find(".item-color").stop()
            .fadeTo(500, 1); 
        $(".navigation-text div")                                    
            .html($(this).parent().parent().parent().find("div.hidden").html())
            .stop()
            .height(0)
            .animate({height: "90px"});
        Pixastic.revert(this);            
    });   
    $(".gray").live("mouseout", function()
    {
        $(this).parent().parent().parent().find(".item-color").stop()
            .fadeTo(500, 0.5);
        $(".navigation-text div")
            .stop()
            .height(0)                       
            .html("");
        Pixastic.process(this, "desaturate");                     
    });
    $(".item-color").bind("click", function()
    {
        top.location.href = $(this).parent().find("a").attr("href");        
    }); 
                                                              
});

function show(from, to)
{
    $(".item").each(function(index)
    {        
        $(this).fadeOut(500);               
    });  
    $(".item").each(function(index)
    {        
        if(index >= from && index <= to)
        {
            $(this).fadeIn(1500);            
        }              
    });           
}
jQuery(window).resize(function(){						 
    if($(document).width() >= 1000)
    {
	   $(".main-site").css("margin-left",($(document).width() / 2 - 530) + "px");
    }
    $(".first-logo").css("margin-top",($(document).height() / 2 - 300) + "px");    	
});
jQuery(window).ready(function(){
    if($(document).width() >= 1000)
    {
	   $(".main-site").css("margin-left",($(document).width() / 2 - 530) + "px");
    }    	    
    $(".first-logo").css("margin-top",($(document).height() / 2 - 300) + "px");	
}); 

$(function() {
    $(".head-d-domen-dot, .head-d-domen").live("mouseover", function()
    {
            $(this).css("cursor","pointer");
			$(".head-d-domen-dot").css("color","#48546A");

    });
});
$(function() {
    $(".head-d-domen-dot, .head-d-domen").live("mouseout", function()
    {
            $(this).css("cursor","pointer");
			$(".head-d-domen-dot").css("color","#263248");
			$(".head-d-domen-dot").css("background","url(templates/default/images/head-dot.png) right 36px no-repeat");
			$(".head-d-domen").css("background","none");
    });
});
