jQuery(document).ready(function($){
    
    var ease_ = "easeOutExpo";
    var dur_ = 350;
    
    
    /*
    $('#dealers .contactForm').each(function(){
        
        var allw = $(this).parent().width();
        var allh = $(this).parents('.contentInner').height(); 
        //var mrgl = (allw - $(this).width())/2;
        var mrgt = (allh - $(this).parent().height())/2;
        
        $(this).css('margin-left',mrgl);
        $(this).css('margin-top',mrgt);
    });
    */
    $('.listingCategory .showInfo').click(function(e){
        var infomask = $('.catDescriptionMask',$(this).parent())
        var height_ = $('.catDescription',$(this).parent()).height();
        if(infomask.height()==0){
            infomask.animate({height:height_},{duration:dur_,easing:ease_}); 
            $(this).html('скрий инфото')
        } else {
            infomask.animate({height:0},{duration:dur_,easing:ease_}); 
            $(this).html('допълнителна информация')
        }
        e.preventDefault();
    })

    $("#nav ul").lavaLamp({ fx: "easeOutExpo", speed: 500 ,target:'a'})
    
    $(".searchHolder .input").Watermark("Търсене");
    $("#email_input").each(function(){$(this).Watermark($(this).val())})
    
    buttonOverState('.blockBulletin .submit_btn', 'hov');
    buttonOverState('.searchHolder .subm', 'hov');
	buttonOverState('.registrationStep2 .input_submit_container .inputSubmit', 'inputSubmitOver');
	
	//button hover
	$('.buttonDark,.buttonLight').hover(function(){$(this).addClass('buttonOver')},function(){$(this).removeClass('buttonOver')})
	
	// Set captcha by JS
	$("input[name='cap_prot']").val('1');
	
	$(".teaser").cycle({
		    fx:     'fade',
		    speed: 800,
		    timeout: 6000, // > 0(miliseconds) to scroll automaticly, 0 for manual scroll
		    pause: false
	});
	
	// 2010-05-21
	var height_home_box_left = $('.boxPromo .shapeTop').height();
	var height_home_box_right = ($('.accentHome').height()-($('.accentHome h2').height()+15)) + ($('.lastNewslist').height());
	//alert("height_home_box_left: " + height_home_box_left);
	//alert("height_home_box_right: " + height_home_box_right);
	var temp = height_home_box_left - height_home_box_right + 5; // 5px is programmed difference in the aligned boxes (which contains links)
	//var temp = height_home_box_left - height_home_box_right; // 5px is programmed difference in the aligned boxes (which contains links)
	//alert(temp);
	
	if( temp>0 ) { //We have case where home_text is smaller - add margin-top for news block to align it!
		//$('.lastNews').css('margin-top', height_home_box_left - height_home_box_right + 5); // 5px is programmed difference in the aligned boxes (which contains links)
		$('.lastNews').css('margin-top', temp);	}
	else if( temp<0 ) {
		// TODO?: How to handle this difference 5px? Now it seems to work
		var temp = height_home_box_right - height_home_box_left + 5; // -35 is converted to +45
		//alert( temp );
		if( temp > 35 ) {
			// skip equalizing!!!It's too much
		} else {
			$('.boxPromo .shapeTop').css('margin-bottom',height_home_box_right-height_home_box_left-10);
		}
	}
	// END 2010-05-21
	
	$('.mapHolder iframe').width(378);
	$('.mapHolder iframe').height(268);
	
	if(typeof(products_rows)=='number'){
    	for(var i = 1;i<products_rows+1;i++){
    	    var mht = 0;
    	    var mhd = 0;
    	    
    	    
    	    $('.blockCatalogue div[class ~= "row_'+i+'"]').each(function(){
    	        if($('.itemTitle',$(this)).height()>mht)mht = $('.itemTitle',$(this)).height();
    	        if($('.itemDescription',$(this)).height()>mhd)mhd = $('.itemDescription',$(this)).height();
    	    })
    	    $('.row_'+i+' .itemTitle').height(mht);
    	    $('.row_'+i+' .itemDescription').height(mhd)
    	    
    	}
	}
});


/* OnOver - add clas for IE - Should be used on elements different from Links */
function buttonOverState(selector, className)
{
	/* Hover over the login button */
	$(selector).hover(function(){
		$(this).addClass(className);
	},
	function(){
		$(this).removeClass(className);
	});
}


function onBefore(){}
function onAfter(){}

