jQuery(document).ready(function(){

  
var skin = $('#default_skin').val();

if ($.cookie("alwahy_home_skin") != null) {
  skin = $.cookie("alwahy_home_skin");

}


$('#reset_skin').click(function(){
  changeCategory($('#default_category').val());
	$('#alwahy_home').css('background', 'url(http://alwahy.com/home/img/skins/images/'+ $('#default_skin').val() +') center center');
});


$('#alwahy_home').css('background', 'url(http://alwahy.com/home/img/skins/images/'+ skin + ') center center');

$('#options_theme').click(function(){
  
	$('#options_theme_box').slideToggle();
	
	change_to = $('#default_category').val();
	
	if($.cookie("alwahy_home_skin_category_id") != null)
	{
		change_to  = $.cookie("alwahy_home_skin_category_id"); 
	}
	
  //$.cookie("alwahy_home_skin_id");
	
	changeCategory(change_to);
});


$("#q").focus();

$('.skin_thumb').click(function(){


    
    $.each($(".skin_thumb"), function(i, item)
    {
      $(item).css({'border':'0', 'display':'inline'});
    
    })      
    
		
		
  rel =  $(this).attr("rel").split(':');
	
  $.cookie("alwahy_home_skin",rel[0], {
  	expires: 999
  });
	$.cookie("alwahy_home_skin_category_id", rel[2], { expires: 999});
	$.cookie("alwahy_home_skin_id", rel[1], {
  	expires: 999
  });
   
	
	$(this).css({'display':'block'}); 
	$(this).css({'border':'2px solid orange'});
	 
  $('#alwahy_home').css('background', 'url(http://alwahy.com/home/img/skins/images/'+rel[0]+') center center');



});

$('#alwahy_services').click(function(){
$('#alwahy_services_box').slideToggle();
});

$('#alwahy_login').click(function(){
$('#alwahy_login_box').slideToggle();
$("#username").focus();
});


$("#close_alexplorer").click(function(){
$("#alwahy_services_box").fadeOut();
});


$("#close_options").click(function(){
$("#options_theme_box").fadeOut();
});


/*
if ($.cookie("already_press") != null) {
 $('#alwahy_home_options').css({
 	'background': 'none'
 }); 
}
*/

$('#alwahy_home_options').hover(function()
{
	//  $.cookie("already_press", 'ok');
		$(this).css({
	  'background': 'none'
	 }); 
});


$("#options_theme").tooltip({
	track: true,
	delay: 0,
	showURL: false,
	extraClass: "tooltip_a",
	top: 30,
	right: 50,
  fade: 250

});





});

function changeCategory(id)
{
	
	$.each($(".mycaro"), function(i, item)
	{
		jQuery('#' + item.id ).hide();
	
	})

  $.each($(".selected"), function(i, item)
  {
      $(item).removeClass();
  
  })
    
		  	
		
		
	
	
	if(id == undefined)
	{
	 var skin_category = $('#default_category').val();	
	}
	else
	{
		skin_category = id;
	}
	
  
	$('#mycarousel_' + skin_category).show();
	 
	
	var start = 0;
	
	var default_skin_key =  $("#default_skin_key").val();
	
  if(default_skin_key > 0 && (parseInt($('#default_category').val()) != parseInt(skin_category) ) == false )
  {
      start  = parseInt( default_skin_key / 5) * 5  + 1;     
  }

	
  if($.cookie("alwahy_home_skin_id") != null)
  {
    start  = parseInt($.cookie("alwahy_home_skin_id") / 5) * 5  + 1;
		
		
		$.each($(".skin_thumb"), function(i, item)
    {
      $(item).css({'border':'0', 'display':'inline'});
    
    })   
		
    $("#skin-" + skin_category + '-' +  $.cookie("alwahy_home_skin_id")).css({'display':'block'}); 
    $("#skin-" + skin_category + '-' + $.cookie("alwahy_home_skin_id")).css({'border':'2px solid orange'});
		
		$.cookie("alwahy_home_skin_id", null);
			
  }

	 
	$('#mycarousel_' + skin_category + ' ul:first-child').jcarousel({
  	'start': start,
		'scroll' : 5
  });

  $("ul#skin_categories li#li_" + id).addClass('selected');


	
  
}
