$(function() {
	
	$('.content-block .acc-container .close').click(function() {
		var block = $(this).parents('.block:eq(0)');
		block.find('.acc-link').toggleClass('acc-link-unactive');
		block.find('.acc-content').toggle().toggleClass('ld-not-opened');
		$(this).toggleClass('not-close');
	});
	
	$('.messages-board table tr:odd').addClass('hover');
	
	$('.dd-button').mouseover(function() {
		$(this).css({'z-index': '1000'});
		$(this).find('.link').addClass('b-hover');
		$(this).find('.dd-content').show();
	}).mouseout(function() {
		$(this).css({'z-index': '10'});
		$(this).find('.link').removeClass('b-hover');
		//alert($(this).find('.dropdown').length);
		$(this).find('.dd-content').hide();
	});
	
	$('.d-article').mouseover(function() {
		$(this).addClass('d-article-hover');
	}).mouseout(function() {
		$(this).removeClass('d-article-hover');
	});
	
	$('.acc-link').click(function() {
		var container = $(this).parent('.acc-container');
		container.find('.acc-content').toggle().toggleClass('ld-not-opened');
		$(this).toggleClass('acc-link-unactive');
		return false;
	});
	$('#profile-page .content-block .acc-container .acc-link').click(function() {
		var container = $(this).parent('.acc-container');
		container.find('.close').toggleClass('not-close');
	});
	
	$('input.ie-field, textarea.ie-field').focus(function () {
		def_val = this.title;
		if (this.value==def_val) {
			this.value = '';
			$(this).css({
				'font-size': '14px',
				'font-weight': 'bold',
				'padding': '5px',
				'color': '#333'
			});
		}
	}).blur(function () {
	    def_val = this.title;
	    if (this.value=='') {
			this.value = def_val;
			$(this).css({
				'font-size': '12px',
				'font-weight': 'normal',
				'padding': '6px 5px',
				'color': '#999'
			});
		}
	});
	
	$('.messages-sorter .search-field').focus(function() {
		def_val = this.title;
		if (this.value==def_val) {
			this.value = '';
			$(this).css({
				'color': '#666'
			});
		}
	}).blur(function() {
		def_val = this.title;
	    if (this.value=='') {
			this.value = def_val;
			$(this).css({
				'color': '#999'
			});
		}
	});
	
	$('.tooltipped').mouseover(function(){
		window.clearTimeout(ti); ti = false;
		
		$('.tooltip').css({'display' : 'none'});
		
		var li = $(this.parentNode);		
		li.css({'z-index': '10'});
		li.find('.tooltip').css({'display' : 'block'});
	});
	$('.tooltip-content').mouseover(function(){
		window.clearTimeout(ti); ti = false;
	})
	$('.tooltipped, .tooltip-content, .tooltip-container').mouseout(function(){
		window.clearTimeout(ti); ti = false; var li;	
		if(this.parentNode.className == 'tooltip'){
			li = $(this.parentNode.parentNode);
		}else {
			li = $(this.parentNode);
		}
		ti = window.setTimeout(function(){
			li.find('.tooltip').fadeOut('slow');	
			$('tr.hover').attr({'class': ''});
		}, 500);
	});
	
	$('.page-slider a').click(function() {
		var idx = this.href.replace(/^.*#/, '');
		set_marker_position($(this).parents('.page-slider'), idx);
		
		//Only For Dotted Sliders
		var ctrl_images = $(this).parents('.page-slider').find('img');
		if ($(this).parents('.page-slider').hasClass('dark-striped')) {
			$(ctrl_images.attr('src', 'css/images/pagination-white-unactive.gif').get(idx)).attr('src', 'css/images/pagination-active.gif');
		} else {
			$(ctrl_images.attr('src', 'css/images/pagination-unactive.gif').get(idx)).attr('src', 'css/images/pagination-active.gif');
		};
		//Only For Dotted Sliders
		var fragment_width = $(this).parents('.page-slider').prev().children('div:eq(0)').children('div:eq(0)').width();
		
		$(this).parents('.page-slider').prev().children('div:eq(0)').animate({
			'left': parseInt(idx * -fragment_width) + 'px'
		}, 800, 'easeInOutQuart');		
		return false;
	});
	
	$('#siteblog-button').mouseover(function() {
		$(this).addClass('hover');
	}).mouseout(function() {
		$(this).removeClass('hover');
	});
	$('#siteblog-button').click(function() {
		$(this).next().toggle();
	});
	$('#siteblog .button-close').click(function() {
		$('#siteblog').hide();
		return false;
	});
	
	$('.activity-feed .article').mouseover(function() {
		$(this).addClass('article-hover');
	}).mouseout(function() {
		$(this).removeClass('article-hover');
	});
	
	$('#profile .mainbox .image').mouseover(function() {
		$(this).find('a').css({'display' : 'block'});
	}).mouseout(function() {
		$(this).find('a').css({'display' : 'none'});
	});
	
	$('#abs-message .close').click(function() {
		$('#abs-message').fadeOut();
		return false;
	});
});

// Clear Inputs
function clearText(input){
    if (input.defaultValue==input.value)
    input.value = ''
}
function restoreText(input){
if (input.value=='')
	input.value = input.defaultValue
}
//End Clear Inputs


var ti = false;
function set_marker_position(context, new_pos) {
	if (new_pos!=$(context).prev().find('.fragment').length-1) {
		$(context).find('a.next').attr({
			href: $(context).find('a.next').attr('href').replace(/\d$/, parseInt(new_pos) + parseInt(1))
		});	
	}
	if(new_pos!=0) {
		$(context).find('a.prev').attr({
			href: $(context).find('a.prev').attr('href').replace(/\d$/, parseInt(new_pos) - parseInt(1))
		});
	}
}
/*
$(document).ready(function(){
  $.preloadCssImages();
});
*/
$(document).ready(function() {
	var preloadedImages = [
		'my-panel-icos.gif', 
		'my-panel-icos-hover.gif', 
		'my-dr-dd-content-2.gif', 
		'my-dr-dd-content.gif', 
		'my-dr-dd-content-a-over.gif', 
		'my-panel-dd-content-a-over.gif'
	];
	var imagesPath = 'css/images/';
	for ( var i=0; i < preloadedImages.length; i++ ) {
		var preloadedImage = new Image();
		preloadedImage.src = imagesPath + preloadedImages[i];
	}
});
