// JavaScript Document

$(document).ready(function(){
    $(".menu_btn").mouseover(function(){
		$(this).css("background-image","url(http://www.obichamvitosha.com/img/bg_menu_selected.gif)");
		$(this).css("background-repeat","repeat-x");
		$(this).css("height","26px");
		$(this).css("height","26px");
		$(this).children("a").css("color","#5d8cc9");
    });
	
	$(".menu_btn").mouseout(function(){
		$(this).css("background-image","none");
		$(this).css("background-repeat","repeat-x");
		$(this).css("height","26px");
		$(this).children("a").css("color","#fff");
    });
	
	document.head_rot = setInterval('rotateHead()',5000);
	document.head_rot_ini = 0;
	
	$('.head_box_text_pack').each(function(x) {
		//$( this ).children('.head_box_desc').get(0).innerHTML  = 'aaaaaaaaaaaaa';								   
         //alert($( this ).children('.head_box_desc').get(0).innerHTML);
		 ellip($('#head_box_desc').get(0), '&hellip;', $( this ).get(0));
	});
	
	if ($("#username").val()) $("#username").css('background-image','url(img/bg_username_off.gif)'); else $("#username").css('background-image','url(img/bg_username_on.gif)');
	if ($("#password").val()) $("#password").css('background-image','url(img/bg_password_off.gif)'); else $("#password").css('background-image','url(img/bg_password_on.gif)');
	
	$("#username").bind('focus', function() { $(this).css('background-image','url(img/bg_username_off.gif)'); } );
	$("#password").bind('focus', function() { $(this).css('background-image','url(img/bg_password_off.gif)'); } );
	$("#username").bind('blur', function() { if (!$("#username").val()) $(this).css('background-image','url(img/bg_username_on.gif)'); } );
	$("#password").bind('blur', function() { if (!$("#password").val()) $(this).css('background-image','url(img/bg_password_on.gif)'); } );
	
	
	
	$('#imagecontrol').bind('click', function(){ if (confirm("Наистина ли искате да изтриете снимката?")) location.href='?del=' + $('#imagecontrol').attr('rel'); } );
	$('#imagecontrol').bind('mouseout', function(){ $('#imagecontrol').css('display','none')} );
	$('#imagecontrol').bind('mouseover', function(){ $('#imagecontrol').css('display','block')} );
	if ($(".userpic img").length) {
		$('.userpic img').bind('mouseout', function(){ $('#imagecontrol').css('display','none')} );
		$(".userpic img").bind('mouseover', function() { 
			var pos = $(this).position(); 
			$('#imagecontrol').css('top',pos.top + 40 + 'px').css('left',pos.left + 60 + 'px').css('display','block').attr('rel',$(this).attr('rel'));
		});
	}
	
});

$(function() {
	if (($('.photo_gallery_img.lightbox a')).length) $('.photo_gallery_img.lightbox a').lightBox();
	if (($('.head_box_img a')).length) $('.head_box_img a').lightBox();
	if (($('.news_img a')).length) $('.news_img a').lightBox();
	if (($('.content_pictures a')).length) $('.content_pictures a').lightBox();
	if (($('.single_img a')).length) $('.single_img a').lightBox();
});

function rotateHead() {
	document.head_rot_ini++;
	if (document.head_rot_ini >= $('.head_box_hidden a.anchor').length) document.head_rot_ini = 0;
	head_box_show(document.head_rot_ini);
}

function head_box_show_ex(i) {
	clearTimeout( document.head_rot );
	head_box_show(i)
}

function head_box_show(i) {
	$('#head_box_title').html($('#head_box_title_' + i).html());
	$('#head_box_desc').html($('#head_box_desc_' + i).html());
	$('#head_box_img').attr('src',$('#head_box_img_' + i).attr('src'));
	
	$('#head_box_a').attr('href',$('#head_box_a_' + i).attr('href'));
	$('.head_box_paging_item, .head_box_paging_item_selected').css('background-color','#578f29');
	$('#head_box_paging_item_'+i).css('background-color','#fff');
	
	$('.head_box_paging_item a, .head_box_paging_item_selected a').css('color','#fff');
	$('#head_box_paging_item_'+i+' a').css('color','#196698');
	
	if (!$('#head_box_desc_' + i).attr('pass')) {
		ellip($('#head_box_desc').get(0), '&hellip;', $( '.head_box_text_pack' ).get(0));
		$('#head_box_desc_' + i).html($('#head_box_desc').html());
		$('#head_box_desc_' + i).attr('pass','yes');
	}
	
	$('#head_box_title').attr('href',$('#head_box_text_a_' + i).attr('href'));
	$('#head_box_desc').attr('href',$('#head_box_text_a_' + i).attr('href'));
	
}