/// javascript document

var imageNum= 1;
var slidesNum= 1;

jQuery.fn.cleanWhitespace = function() {
    textNodes = this.contents().filter(
        function() { return (this.nodeType == 3 && !/\S/.test(this.nodeValue)); })
        .remove();
    return this;
}

function getImage(a)
{
	
	d= $(a).attr('id');
	//alert(d);return;
	d= d.split('_');
	imageNum= d[1];
	imageNum++;
	if(imageNum > slidesNum){
		imageNum= slidesNum;
	}
	
	if($('#slideDetail_' + imageNum)){
		$('.slideDetails').css('display','none');
		$('.slideImages').removeClass('activeSlide');
		
		a[1].className+= ' activeSlide'
		//$('#slideImage_' + imageNum).addClass('activeSlide');
		
		$('#slideDetail_' + imageNum).css('display','block');
	}
	
	//slideImage(imageNum);
	//alert("After animation ends:" + a);
}


function getPoll(form)
{
	elm= $(form).parent();
	$(elm).html('<img style="margin:40px 90px" src="' + BASE_DIR + 'images/ajax-loader2.gif">')
	
	$.ajax({
		type:"POST",
		url: $(form).attr('action'),
		data: $(form).serialize(),
		success: function(html){
			$(elm).html(html);
		},
	});
	
	return false;
}



function valid(frm)
{
	var cvh= true;
	$(frm).find('.required').each(function(){
		if($(this).val().trim() == ''){
			if(cvh){
				$(this).focus();
				cvh= false;
			}
		}
	});
	
	return cvh;
}


$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	
	/// currency 
	window.setInterval('getcurs()',30000);
	
	/****** tabs 1 ******/
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$("#tab_container1 .tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$("#tab_container1 .tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	/******************************************/
	
	
	/****** tabs 2 ******/
	$("ul.tabs2 li:first").addClass("active").show(); //Activate first tab
	$("#tab_container2 .tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs2 li").click(function() {
		$("ul.tabs2 li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$("#tab_container2 .tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	/******************************************/
	
	
	/****** tabs 3 ******/
	$("ul.tabs3 li:first").addClass("active").show(); //Activate first tab
	$("#tab_container3 .tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs3 li").click(function() {
		$("ul.tabs3 li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$("#tab_container3 .tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	/******************************************/
	
	/// menu roll
	$("#primary-menu li a").hover(function(){
		xsi= $(this).attr('id');
		xsi= xsi.split('_');
		id= 'second_menu_'+ xsi[2];
		$('.secondary_menu').hide();
		
		if($('#' + id)){
			$('#' + id).show();
		}
		
	});
	
	
	slidesNum= $('#slider ul li').length;
	
	/// slide
	if($("#slider") && $(".slideImages").length > 0){
		$(function() {
			$(".carousel").jCarouselLite({
				btnNext: ".next",
				btnPrev: ".prev",
				horizontal: true,
				hoverPause:true,
				visible: 3,
				auto:5000,
				speed:1000,
				beforeStart:getImage,
			});
		});
	}
	
	$('#n_1').addClass('activeSlide');
	
	////// rating
	$('input.wow').rating();
	$('#rate a').click(function(){
		if($('input.wow').attr('disabled')){
			return false;
		}
		
		$.ajax({
			type:"POST",
			url: window.location,
			data: 'rate=' + $(this).text(),
			success: function(html){
				$('input.wow').rating('disable');
				$('input.wow').attr('checked',false);
				
				tra= 'rate_' + html;
				if(document.getElementById(tra)){
					document.getElementById(tra).checked= true;
				}
				//$(tra).('checked',true);
				
				$('input.wow').rating('enable');
				$('input.wow').rating('disable');
			},
		});
		
	});
	
	
	$('.news-content').click(function(){
		//$('#curs_list, #details_list').css('display','none');
	});
	
	
	/// nnews
	$('#sidenews td').hover(function(){
		$('#sidenews td').removeClass('anews');
		$(this).addClass('anews');
		nd= $(this).find('a').attr('rel');
		$('.nnews').css('display','none');
		$('#nnews_' + nd).css('display','block'); 
	});
	
});



function getcurs()
{
	$.ajax({
		type:"GET",
		url: BASE_DIR + DEFAULT_LANG + '/' + DEFAULT_BORSA + '/currency/curs.html',
		success: function(html){
			
			$('#current-currency').html(html);
			
		},
	});
	
	return false;
}


var dj;
function _updateHtml(elm)
{
	if(dj){
		dj.abort();
	}
	
	ti= 0;
	
	dj= $.ajax({
		url: $(this).attr('href'),
		async: false,
		success: function(html){
			$(elm).html(html);
			if(typeof makeInterval == 'function'){
				makeInterval();
			}
		}
	});
	
}

var jnw;
function get_html(elm)
{
	window.clearTimeout(jnw);
	_updateHtml($('#main-table'));
}


