var switchSlide = function() {
	
	if($('.slides_container div.slide-element.first').is(':visible')||$('.slides_container div.slide-element.second').is(':visible')) {
		clearInterval(INTERVAL);
		setTimeout("delaySlide();", 5000);
		return;
	}
	
  var current = $('.slides_container div.slide-element:visible');
  if(!current.next().attr('class')) {
    next = $('.slides_container div.slide-element:first');
  } else {
    next = current.next();
  }
  current.fadeOut(600);
  next.fadeIn(600);
};

var delaySlide = function() {
	var current = $('.slides_container div.slide-element:visible');
	next = current.next();
	current.fadeOut(600);
  next.fadeIn(600);
	INTERVAL = setInterval("switchSlide();", 7000);
};

$(document).ready(function(){
// rel=external for links because target ="_blank" is deprecated   
	$("a[rel$='external']").attr('target','_blank');
	   
//the accordion menu 
	$("dl dt.open").next().show();
//	$("dt a").click(function(){
//	  if($($(this).parent().next()).get(0).tagName.toLowerCase() == 'dd') {
//  		$("dd:visible").slideUp('fast');
//  		$(this).parent().next().slideToggle('fast');	
//  		return false; //this is used to set the link to not go anywhere onClick
//	  }
//	  return true;
//	});
	
	$(".searh_text_box").click(function(){
		if(this.value == 'Căutare...' || this.value == 'Search...'){
			this.value = '';
		}	
	}); 
	$("#forgot_pass").click(function(){
		$(".forgot_pass").slideToggle('fast');	
	});	
//licitatii table styling	
	$("table.licitatii tr:odd").css("background", "#f3f3f3");
	$("table.licitatii tr td").css("width", "100px");
	
//carusel script
//	$('#slides').slides({
//		  play: 6000,
//    	//pause: 5000,
//    	//hoverPause: true,
//    	fadeSpeed: 250,
//    	effect: 'fade',
//		generateNextPrev: false,
//		pagination: false
//	});	

//locations map
	$(".oras").hover(function(){
		var spanWd = $(this).children("span").width();
		var infoPos = $(this).children(".oras_info").width();
		//alert (centerPos);
		$(this).children(".oras_info").stop(true, true).slideDown('fast').css("left", -125+(spanWd/2));		
	}, function(){
		$(".oras_info").slideUp('fast');
	});	
	
// sitemap styling last child
    $('.sitemap li:last-child').addClass('last');	
    
// aplica credit form
	$("form#aplica").css("display", "none");
	$('a[href="#formular"]').click(function(){
	  if(!$('form#aplica').is(':visible')) {
  		$("form#aplica").show();
	  }
	});   	
});
function number_format (number, decimals, dec_point, thousands_sep) {
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);            return '' + Math.round(n * k) / k;
        };
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');    }
    return s.join(dec);
}
jQuery.expr[':'].regex = function(elem, index, match) {
    var matchParams = match[3].split(','),
        validLabels = /^(data|css):/,
        attr = {
            method: matchParams[0].match(validLabels) ? 
                        matchParams[0].split(':')[0] : 'attr',
            property: matchParams.shift().replace(validLabels,'')
        },
        regexFlags = 'ig',
        regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
    return regex.test(jQuery(elem)[attr.method](attr.property));
}
jQuery.fn.scrollTo = function(speed)
{
  var speed = (speed) ? speed : 1200;
  destination = $(this).offset().top;
  //$("html:not(:animated),body:not(:animated)").animate({
  $("html,body").animate({
      scrollTop: destination
    }, {
         duration: 1200,
         specialEasing: {
           bottom: 'linear'
         }
       }
  );
}
function trim (str, charlist) {
        i = 0;
    str += '';
 
    if (!charlist) {        // default list
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {
        // preg_quote custom list
        charlist += '';        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
    }
 
    l = str.length;
    for (i = 0; i < l; i++) {        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(i);
            break;
        }
    } 
    l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);            break;
        }
    }
 
    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';}
