
jQuery(document).ready(function(){
	// toggle boxesjQuery
    jQuery('a.toggle').click(function(){
        var el = jQuery(this).parent().parent().parent().find('div.box-body');
        if(el.css('display')!='none'){
            el.slideUp('slow');
            jQuery(this).removeClass('close').addClass('open');
        }else{
            el.slideDown('slow');
            jQuery(this).removeClass('open').addClass('close');            
        }
        return false;
    });
	
	// apply 'imagelink' class to images in the main content
	jQuery('a img').parent('a').addClass('imagelink');
	// apply 'textlink' class to regular links in the main content
	jQuery('p a').addClass('textlink');
	//$('#main-entry-container ul li a').addClass('textlink');
	// apply 'textlink' class to author box links
	jQuery('p.generic-text a').addClass('textlink');
	// apply 'citelink' class to links in block quote
	jQuery('blockquote a').addClass('citelink');
	
	// attach a function to the quote comment link
	jQuery('a.quote-comment').click( function() { 
		var tb = $('#comment');
		var strQuote = $(this).attr('title');
		// assign the value
		tb.val('<blockquote>' + strQuote + '</blockquote>');
		return false;
	 });
	
	// assign blockquote styles to comment boxes
	jQuery('div.box-body blockquote').addClass('blockquote-quote');

    duplicateForm();
    showDetailsForm();
    validateForms();
});

function duplicateForm(){
	
	if(jQuery('#question_in_post').html()!=null && jQuery('#question_in_post').html().toLowerCase().indexOf('<form')<0){
		jQuery('#question_in_post').append(jQuery('#concurs_Question div.box-body').html());
		jQuery('#question_in_post').find('form').attr('id', 'concursForm_inPost');
		jQuery('#question_in_post').find('strong').hide();
	}
}

function showDetailsForm(){
    jQuery('.questionAnswerBox').keypress(function(){
        if(jQuery(this).val()!='')
            jQuery(this).parent().parent().find('.formDetails').slideDown('slow');
    });
}

function validateForms(){
    jQuery('input.submit').click(function(){
        if(jQuery('#concursForm').length>0)
            jQuery('#concursForm').validate({submitHandler:function(form){
                    pageTracker._trackPageview("/comment-add.html" );
                    jQuery('#concursForm').submit();
            }});
        if(jQuery('#concursForm_inPost').length>0)
            jQuery('#concursForm_inPost').validate({submitHandler:function(form){
                pageTracker._trackPageview("/comment-add.html" );
                jQuery('#concursForm_inPost').submit();
            }});
    });
}

function fillWidgetCode(url){
    html = '<a href="'+HTTP_ADDRESS2+'" target="_blank" title="Sustin Turneul sCool Eco Tour initiat de Euro-GSM si NOKIA">';
    html += '<img src="'+url+'" alt="Sustin Turneul sCool Eco Tour initiat de Euro-GSM si NOKIA" /></a>';

    $('#widgetsEmbedCode').val(html);
}
