/*
 * General js stuff
 */
function FCKValue(id)
{
    var temp = document.createElement('txBuffer');
    temp.value = FCKeditorAPI.GetInstance(id).GetXHTML();
    return temp;
}

function $() {
        
	if (arguments.length>1) {
		return false;
	}
	if (arguments.length<1) {
		return false;
	}

	var element = arguments[0];

    if (typeof element == 'string') {
        if (document.getElementById) 
        {
            try 
            {
                element = FCKValue(element);
            }
            catch(err)
            {
                element = document.getElementById('ctl00_cpBody_'+element);            
            }

        } else if (document.all) {
            element = document.all['ctl00_cpBody_'+element];
        }
    }
    
	
	return element;
}

function Search()
{
    n = document.getElementById('ctl00_txSearch').value;
    document.location = "/rezultateleCautarii.aspx?n="+n;
}

function toggleElement(handle,content,additionalContent){
    if (additionalContent) { 
        if (handle.is(':checked')) {
            additionalContent.fadeOut('fast',
                function(){
                    content.fadeIn('fast');
                }
            );   
        } else {
            content.fadeOut('fast',
                function(){
                    additionalContent.fadeIn('fast');
                }
            ); 
        }
    
    } else {
        if (handle.is(':checked')) {
            content.fadeIn('fast');
        } else {
            content.fadeOut('fast');
        }
    }
}


 
//jQuery.noConflict();

jQuery(function($) { 
	
	
	/*
	 * Inline Shopping Cart
	 */
	
	// We hide it initially
	$('#inlineCart').hide();
	
	//Add event handler to open the cart on hover
	$('#inlineCartWrapper').hoverIntent(
		function(){
			$('#inlineCartWrapper').addClass('active');
			$('#inlineCart').slideDown("fast");
		},
		function(){
			$('#inlineCart').slideUp("fast",function(){
				$('#inlineCartWrapper').removeClass('active');
			});
		}
	);
	
	//Only let users type in numeric characters
	$('#inlineCartWrapper').find('input').numeric();
	$('#buy input').numeric();
	
	//Clone the Finalize and How To links into the small Cart
	//We do this to avoid duplicate links. No need of a js fallback => without js, noone is able to see the cart
	$('#inlineCartBar').find('a.finalizeOrder, a.howToBuy').clone().appendTo($('#buyButtons'));
	
	$('.buy input').numeric();
	
	/*
	 * Search Box
	 */
	var searchLabel = $('#search label');
	var labelText = searchLabel.text();
	var searchInput = $('#search input:text');
	
	//Setting the label to overlay the actual input
	searchLabel.show();
	
	//Hiding the label when focusing the field
	searchInput
		.focus(function(){
			searchLabel.hide();
		})
		
    //Submitting on enter
		.keyup(function(e){
		    if (e.keyCode == 13) {
		       $(this).siblings(':button').click();
		    }
		})
	
	//Reshowing it if there is no input
		.blur(function(){
			if ($(this).val() == '') {
				searchLabel.show();
			}
		});
	
	/*
	 * IE fix
	 */
	//Filter IE
	if ($.browser.msie) {
		$('#nav>li>ul>li:last-child').addClass('last-child');
		
		//AboutNav separators
		aboutNavLi = $('#aboutNav>li').not(':first-child');
		aboutNavLi.prepend(' | ');
		
		$('input:text, input:password, textarea')
		    .focus(function(){ $(this).addClass('focus'); })
		    .blur(function(){ $(this).removeClass('focus'); });
		
		//Filter IE6
		if ($.browser.version == 6) {
			
		}
	}
	
	
	
	/*
	 * Navigation Animation
	 */
	var nav = $('#nav');
	var active = nav.find('li.active');
	
	//Setting active classes
	active.parents('li').addClass('active');
	
	//Hiding non active elements
	nav.find('li').not('.active').find('>ul').hide();
	
	//Setting a click event on level 1 & 2 links
	//which will return false as only lvl 3 links are real
	var a = nav.find('>li>a');
	a.click(function(){
		var li = $(this).parent();
		
		//Hiding other branches
		var siblings = li.siblings();
		siblings.find('>ul').slideUp('normal');
		
		//Removing the 'active' class from the other branches
		siblings.removeClass('active');
		
		//Showing this particular branch
		li.find('>ul').slideDown('normal');
		
		//Setting the 'active' class
		li.addClass('active');
		
		//Returning false as this link has only animation purposes
		//return false;
	});
	
	
	
});