/* tycktill och inloggning */
var romeo;
var $j = jQuery.noConflict();
$j(document).ready(function(){
	$j('div.widget_custom-contact-forms h2').click(function (e) {
		$j('div.widget_custom-contact-forms form').modal();
		return false;
	});
	$j('div.button').click(function(e) {
			romeo = $j(this);
			$j(this).children('.content').modal({
				minHeight:400,
				minWidth: 400
			});
			var found = $j('#simplemodal-data').find('video');
			if(found.length > 0) {
				document.getElementById('simplemodal-data').getElementsByTagName('video')[0].play();
			}
			found = $j('#simplemodal-data').find('.autoexec');
			if(found.length > 0) {
				document.location.href = $j('#simplemodal-data').find('a').attr('href');
			}
			return false;
		}
	);
	$j('.accordion h2').click(function() {
		$j(this).next().toggle('slow');
		return false;
		}).next().hide();
	saltaby_place("<h2>Lämna synpunkter</h2>",$j('div.widget_custom-contact-forms form'));
	saltaby_fix_form();
	saltaby_fix_login();
	// adjust annoying ex
	$j('a.close').html('&times;')
	fix_all_addies();
});
function saltaby_place(text, where) {
	return $j(text).prependTo(where);
}
function saltaby_fix_form() {
	// Fix low quality html
	$j('div.widget_custom-contact-forms form > div').each(function(index) {
		class_name = $j(this).find('input').attr('class')
		$j(this).addClass(class_name);
	});
	$j('div.widget_custom-contact-forms form > div > div').each(function(index) {
		$j(this).addClass('field_'+index);
	});
	$j('div.widget_custom-contact-forms input, div.widget_custom-contact-forms textarea').each(function(index) {
		name = $j(this).attr('name')+'_'+index;
		$j(this).attr('id',name);
		$j(this).next().attr('for',name);
		$j(this).prev().attr('for',name);
	});
	$j('input.comment_category').click(function() {
		label = $j(this).parent()
		label.addClass('checked');
		label.siblings().removeClass('checked');
	});
	saltaby_place('<p class="info"><b>Svar.</b> Om du vill ha svar från oss så glöm inte att ange din e-postadress</p>',$j('div.email'));
	// self-labeling aka placeholder
	$j('div.widget_custom-contact-forms input[type="text"], div.widget_custom-contact-forms textarea').each(function(i,el) {
		el = $j(el);
        var ph = el.prev().text();
		ph = ph.replace('* ','');
		el.prev().remove();
        if (!ph) return true;

        el.addClass('placeholder');
        el.attr('value', ph);

        el.focus( function(e) {
            if( el.val()==ph ) {
                el.removeClass('placeholder');
                el.attr('value', '');
            }
        });

        el.blur( function(e) {
            if( $j.trim(el.val())=='' ) {
                el.addClass('placeholder');
                el.attr('value', ph);
            }
        });
	});
}
function saltaby_fix_login() {
	$j('label[for="user_login"]').text('Användarnamn');
	$j('label[for="user_pass"]').text('Lösenord');
	$j('label[for="rememberme"]').text('Kom ihåg mig');
	$j('.sidebarlogin_otherlinks a').text('Har du glömt ditt lösenord?');
	saltaby_place("<h2>Logga in på intranätet</h2>",$j('.widget_wp_sidebarlogin form'));
}
