var captchaCode = '';
$(document).ready(function(){
   $('div#Menu li').hover(function(){
                var w = $(this).find('ul').width();
                var p_w = $(this).width(); 
                if(w<p_w)
                    $(this).find('ul').css('width', p_w+'px');
                $(this).find('ul').css({left:'auto', display:'none'});
                $(this).find('ul').slideDown('600');
            },
           function(){
               $(this).find('ul').css('left', '-2000px');
           });

    $('h3, .pgContent h1').each(function(){
		var txt = '<span>'+$(this).text()+'</span>';
		var obj = $(this).clone();
		var obj2 = $(this);
		$(this).html(txt);
		obj.find('a').each(function(){ obj2.append($(this)); });
		
		
		$(this).find('a').each(function(){if($(this).html().length<7)$(this).html('');})
		$(this).find('a').lightBox();
    });
	

    $('input, textarea, select').focus(function(){
        $(this).css('border-color', '#FF931E');
        $(this).prev('label').css('color', '#FF931E');
        $(this).next('.error').fadeOut(500);
    }).blur(function(){
        $(this).css('border-color', '#DFDFDF');
        $(this).prev('label').css('color', '#666666');
    });
	
	if($('img.header').parent('p').length>0){
		var temp_html = $('img.header').parent('p').html();
		var parent = $('img.header').parent('p').parent();
		$('img.header').parent('p').remove();
		parent.prepend(temp_html);
	}
	getCaptchaCode();

    if($('#slider').find('.slide').length){
        setInterval(function(){
            var current = $('#slider').find('.slide:visible:first');
            var next = current.next('.slide');
            if(!next.length){next = $('#slider').find('.slide:first');}
            current.fadeOut(1000);
            next.fadeIn(1000)
        }, 3500);
    }
});

function getCaptchaCode(){
	$.get(HTTP_ADDRESS+"captcha.php", { genew: "no", time:new Date() },
	   function(data){
			var obj = $('.pgContent form');
			captchaCode = data;
			if(obj.length){
				obj.each(function(){
					if(!obj.find('input[name=captcha_code]').length)
						obj.prepend('<input type="hidden" name="captcha_code" value="'+data+'"');
				});
			}
	   });
}
