var $j = jQuery.noConflict();

$j(document).ready(function(){

    // mHide = function () {
        // $j("ul.submenu",this).animate({width:"0px",opacity:0.95},200,'swing').dequeue();
    // };

    // mShow = function () {
        // $j("ul.submenu",this).animate({width:"328px",opacity:0.95},200,'swing').dequeue();
    // };

    // $j(function() {
        // $j("li.menuitem").hover(mShow,mHide);
    // });

	
	$j('#messagebox').fixedCenter();

    $j('div.catdesc').hide();

    $j('a.teljes,a.rovid').click(function() {
        $j('div.catdesc').slideToggle('slow');
        return false;
    });

    $j('.search_category').click(function() {        
		$j('.catdrop').slideToggle('slow');
    });
	
    $j('.swCategory').click(function() {        
		var  secc = $j(this).attr('class').split(' ')[1];
		var cid = secc.split("_")[1];
		$j("input[name='schincategory']").val(cid);
		$j('.schetxt').text($j(this).text());
    });
	
    $j('.kiemelt_menu_items').hover(
    function(){
        var a = $j(this);
        var panel = $j(this).find('.kiemelt_sub_item');
        a.addClass('needhover');
        setTimeout(function(){
            if (a.hasClass('needhover')) {
                panel.css('display','block');
            }
        },500);
    },
    function(){
        var a = $j(this).removeClass('needhover')
            .parent().find('.kiemelt_sub_item').hide();
        $j(this).stop(true, true);
    }
    ); 

	$j('.addtoform').addClass('dontsubmit');
	$j('.addtoform').submit(function(){
		if ( $(this).hasClass('dontsubmit') ) {
			return false;
		}
		return true;
	});
	
	$j('.addtoform input.button, .addtoform_browse input.button, #flysubmitbutton').click(function(e) {
		$j('#MSG_overlay').show();
		$j('#messagebox').show();
		
		var clickedForm = this.form;

		var selectedProduct = $j(clickedForm).find(':input[name=product_id]').val();
		var selectedProductQuantity= $j(clickedForm).find(':input[name=quantity]').val();
		$j('#messagebox').find(':input[name=product_id]').each(function(i){
			$j(this).val(selectedProduct);
			//console.log(this, i);
		});
		$j('#messagebox').find(':input[name=quantity]').each(function(i){
			$j(this).val(selectedProductQuantity);
			//console.log(this, i);
		});
        $j('#messagebox').find(':input[name=redirecturl]').each(function(i){
            var red = $j(this).val()+'#prod_'+selectedProduct;
			$j(this).val(red);
			//console.log(this, i);
		});
	});

	
});

function switchpanels(cbid, panel1) {
	if(!cbid||!panel1) return false;
	if($j(cbid).is(":checked")) {
		$j(panel1).show("slow");
	} else {
		$j(panel1).hide("slow");
	}
}

(function(){
	jQuery.fn.fixedCenter = function(){
		return this.each(function(){
			var element = jQuery(this), win = jQuery(window);
			centerElement();
			
			jQuery(window).bind('resize',function(){
				centerElement();
			});

			function centerElement(){
				var elementWidth, elementHeight, windowWidth, windowHeight, X2, Y2;
				elementWidth = element.outerWidth();
				elementHeight = element.outerHeight();
				windowWidth = win.width();
				windowHeight = win.height();	
				X2 = (windowWidth/2 - elementWidth/2) + "px";
				Y2 = (windowHeight/2 - elementHeight/2) + "px";
				jQuery(element).css({
					'left':X2,
					'top':Y2,
					'position':'fixed'
				});						
			} //centerElement function
		});
	}
})();

