$(document).ready(function() {
	// $("div.menu li a").mouseover(function() {
	//	$(this).parent('li').toggleClass('over');
	// });
	// 
	// $("div.menu li a").mouseout(function() {
	//	$(this).parent('li').toggleClass('over');
	// });

	$("input.flop").each(function(){
		$(this).attr("flopvalue", $(this).val())
	})
	
	$("input.flop").focus(function(){
		if ( $(this).val() == $(this).attr("flopvalue") ) {
			$(this).val("");
			$(this).addClass("focus")
		}
	})

	$("input.flop").blur(function(){
		if ( $(this).val() == $(this).attr("flopvalue") || $(this).val() == "" ) {
			$(this).val( $(this).attr( "flopvalue") );
			$(this).removeClass("focus");
		}
	})


	$("table.prices tr td:last-child").addClass("last");
	$("table.prices tr td:first-child").addClass("first");

	$("table.prices tr").mouseover(function() {
		$(this).toggleClass('hilite')
	});

	$("table.prices tr").mouseout(function() {
		$(this).toggleClass('hilite')
	});

	$(".box_corner6").wrapInner('<div class="box_corner6_inner"></div>')
	$(".box_corner6").prepend('<div class="corner6 TL"></div><div class="corner6 TR"></div><div class="corner6 BL"></div><div class="corner6 BR"></div>')


	$("#link_status").overlay({
		speed: 'fast', 
		// left: -800,
		// zIndex: 1001,
		// closeOnClick: false,
		expose: { color: '#000000', opacity: 0.5, closeSpeed: 1000 }
	})

	$(".link_reg").overlay({
		speed: 'fast', 
		// left: -800,
		// zIndex: 1001,
		// closeOnClick: false,
		expose: { color: '#000000', opacity: 0.4, closeSpeed: 200 },
		onBeforeLoad: function() {
			$("#overlay_reg_box").load("/accounts/register/ #ajax_reg", function(){
				// еще раз применяем стили к загруженному документу
				apply_styles()
				Cufon.replace('#ajax_reg h1');
			})
		},

		onLoad: function() {
			$("#id_first_name").focus()
		}
	});

	
	$(".q_example").click(function (){
		$("#q").val( $(this).text() )
	})
	
    // $(".link_status").tooltip({
    //     events: {
    //         def: "click, blur mouseout"
    //     },
    //  position: ['center', 'left'],
    //  opacity: 0.9,
    //  tip: '#box_status',
    //  offset: [5, -25],
    //  delay: 1000,
    //  effect: 'sideslide'
    //  // fadeInSpeed: '50',
    //  // fadeOutSpeed: '500',
    //         // onBeforeShow: function(e) {
    //         //  setTimeout(function(){ $("input#status_client").focus();  }, 1500)
    //         // },
    //         // onHide: function(e) {
    //             // $("input#status_client").blur()
    //         // }
    // });

    qtip_style = {
        color: 'white',
        background: '#454647',
        border: {
            width: 10,
            radius: 6,
            color: '#454647'
        },
        name: 'dark',
        // tip: 'bottomRight'
        tip: true
    }
    $(".link_status").qtip({
        content: $(".box_status_input").remove(),
        show: {
            when: {
                event: 'click'
            },
            delay: 0,
            effect: {
                type: 'fade'
            },
            target: $('a.link_status')
        },
        style: qtip_style,
        position: {
            corner: {
                target: 'topLeft',
                tooltip: 'rightBottom'
            },
            container: $("#form_status")
        },
        hide: {
            when: {
                event: 'unfocus'
            },
            effect: {
                type: 'fade',
                length: 500
            },
            fixed: true
        }
    })

    // $(".link_status").qtip({content: "yoganada"})

    // status_tip = $(".link_status").qtip('api')
    // status_tip.onShow = function(){
    //     $("#status_client").focus()
    // }
    $(".link_status").click(function(){return false})
	
    apply_styles()

	$("img[rel]").overlay({expose: { color: '#000000', opacity: 0.4, closeSpeed: 200 }});
	
	$("a.link-login-box").click(function(){
	    $("#cart-box").slideUp('fast', function(){
	        $("#login-box").slideDown('fast')
	    })
	    return false
	})
});

// для IE, который не понимает новые селекторы
function apply_styles () {
	$("input[type=text]").addClass("dark")
	$("input[type=password]").addClass("dark")
	$("textarea").addClass("dark")

	$("input[type=text]").addClass("input_text")
	$("input[type=password]").addClass("input_text")
	$("textarea").addClass("input_text")

	$("ul li:last-child").addClass("li_last")

	$("#q").removeClass("dark")
}


$.tools.tooltip.addEffect("sideslide",	
	 
	// opening animation 
	function() {  
		var opacity = this.getConf().opacity; 
		this.getTip().css({opacity:0}).animate({left: '+=10', opacity:opacity}, 100).show(); 
	},	
	 
	// closing animation 
	function() { 
		this.getTip().animate({left: '-=30', opacity:0}, 200, function() {  
				$(this).hide().animate({left: '-=30'}, 0); 
		}); 
	} 
);

