var effect = 'fade';

jQuery.fn.placeHolder = function(default_value) {
	var el = jQuery(this);
	default_value = default_value || el.attr('placeholder');
	
	if(default_value && default_value.length) {
		el.focus(function() {
			if(el.val() == el.data('default_value')) el.val('').removeClass('empty');
		});

		el.blur(function() {
			if(!el.val().length) el.val(el.data('default_value')).addClass('empty');
		});

		el.closest('form').submit(function() {
			if(el.val() == el.data('default_value')) el.val('');
		});

		el.data('default_value', default_value).attr('title', default_value).trigger('blur');
	}
	
	return this;
};

jQuery(function($) {

	var linkz = [];

	$('#slider a').each(function(i) {
		linkz.push($(this).attr('rel', i).attr('href'));
	});
	
	if($.browser.msie) {
		$('body').addClass('is-ie');
		if($.browser.version == 7) $('body').addClass('is-ie7');
		if($.browser.version == 8) $('body').addClass('is-ie8');
	}

	$('#widget-s').placeHolder();

	$('#slider').cycle({
		fx:					effect,
		after:	function(i, el) {
			link = linkz[$(el).attr('rel')];
			$('#slider a').attr('href', link);
		}, 
    	pager:  '#slider-nav'
	});

	$('#header ul li a').each(function(i, el) {
		el = $(el);
		el.html('<span>' + el.html() + '</span>');
	});
	
	var csss = ['', 'small', 'smaller', 'big', 'biger', 'light', 'dark', 'blue'];
	$('.tag-cloud a').each(function(i, el) {
		$(el).addClass(csss[Math.floor(Math.random()*csss.length)]);
	});

	$('.widget_nav_menu ul li a').each(function(i, el) {
		$('<span class="s' + i + '">' + i + '</span>').insertBefore($(el));
	});

	$('.footer-nav a').each(function(i, el) {
		if($(el).attr('href') == 'http://') $(el).removeAttr('href');
		if(i) {
			$('<span>|</span>').insertBefore($(el));
		}
	});

	var mts = {a1: [], a2: [], a3: []}, iz = 0, tag_o = 0;
	$('.tag-cloud li').each(function(i, el) {
		el = $(el);
		if(tag_o != el.offset().top) { iz++; tag_o = el.offset().top }
		mts['a' + iz].push(el);
	});
	$.each(mts, function(i, item) {
		var w = 0;
		$.each(item, function(j, el) {
			w += $(el).width();
		});
		$(item[0]).css('margin-left', (900 - w) / 2 - 45);
	});

});

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21966179-1']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
