var direction = 'right';
var tabImages = [];
tabImages['business'] = 'tabs-home-1.png';
tabImages['social-politic'] = 'tabs-home-2.png';
tabImages['sport-special-interest'] = 'tabs-home-3.png';
tabImages['women-entertainment'] = 'tabs-home-4.png';

function switch_page(language, categoryId) {
	$.ajax({
		url: baseURL + '/index/switch_page/' + categoryId,
		data: 'language=' + language,
		type: 'POST',
		async: false,
		dataType: 'json',
		success: function(data) {
			if(language == 'ro') {
				$('#romanian').attr('href', data);
			} else {
				$('#english').attr('href', data);
			}
		}
	});
}

function switch_item(language, groupId) {
	$.ajax({
		url: baseURL + '/index/switch_item/' + groupId,
		data: 'language=' + language,
		type: 'POST',
		async: false,
		dataType: 'json',
		success: function(data) {
			if(language == 'ro') {
				$('#romanian').attr('href', data);
			} else {
				$('#english').attr('href', data);
			}
		}
	});
}

function switch_photo(language, groupId, fileId) {
	$.ajax({
		url: baseURL + '/index/switch_photo/' + groupId,
		data: 'language=' + language + '&file_id=' + fileId,
		type: 'POST',
		async: false,
		dataType: 'json',
		success: function(data) {
			if(language == 'ro') {
				$('#romanian').attr('href', data);
			} else {
				$('#english').attr('href', data);
			}
		}
	});
}

function next() {
	if(jQuery("#flip").jcoverflip("current") == jQuery("#flip").jcoverflip("length") - 1) {
		direction = 'left';
	} else if(jQuery("#flip").jcoverflip("current") == 0) {
		direction = 'right';
	}
	
	if(direction == 'left') {
		jQuery("#flip").jcoverflip("previous");
	} else {
		jQuery("#flip").jcoverflip("next");
	}
}

function slideshow(nr) {
	var step = Math.ceil((100/nr)*10)/10;
	var currentItem = Math.round(nr/2);

	$('#flip').jcoverflip({
      current: currentItem,
      beforeCss: function( el, container, offset ){
    	el.find('img').attr('src', el.attr('thumb')).parent().removeClass('ui-jcoverflip--shadow');
        return [
          $.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 308 - 182*offset)+'px', bottom: '40px' }, { } ),
          $.jcoverflip.animationElement( el.find('img'), { width: '168px', height: '161px' }, {} )
        ];
      },
      afterCss: function( el, container, offset ){
    	el.find('img').attr('src', el.attr('thumb')).parent().removeClass('ui-jcoverflip--shadow');
        return [
          $.jcoverflip.animationElement( el, { left: ( container.width( )/2 + 125 + 182*offset)+'px', bottom: '40px' }, { } ),
          $.jcoverflip.animationElement( el.find('img'), { width: '168px', height: '161px' }, {} )
        ];
      },
      currentCss: function( el, container ){
    	el.find('img').attr('src', el.attr('main')).parent().addClass('ui-jcoverflip--shadow');
        return [
          $.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 125 )+'px', bottom: 0 }, { } ),
          $.jcoverflip.animationElement( el.find('img'), { width: '235px', height: '225px' }, { } )
        ];
      },
      change: function(event, ui){
        $('#slider-home_scrollbar').slider('value', ui.to*step);
      }
    });
	
	 $('#slider-home_scrollbar').slider({
          value: 50,
          stop: function(event, ui) {
            if(event.originalEvent) {
              var newVal = Math.round(ui.value/step);
              $('#flip').jcoverflip( 'current', newVal );
              $('#slider-home_scrollbar').slider('value', newVal*step);
            }
          }
        });
        
        setInterval('next()', 30000); 
}

$(document).ready(function(){
	/*************************************************** menu */
	$("#menu > LI").hover(
	    function() {
	        //$(this).children("DL").slideDown(20);
			$(this).addClass('activ');
	    },
	    function() {
	        //$(this).children("DL").slideUp(20);
			$(this).removeClass('activ');
	    }
	);

	/************************************ okidoki search over */
	$(".box-okidoki DIV INPUT.submit").hover(
	    function() {
			$(".box-okidoki").css("backgroundPosition","0 -74px");
			$(this).addClass('submitOv');
	    },
	    function() {
			$(".box-okidoki").css("backgroundPosition","0 0");
			$(this).removeClass('submitOv');
	    }
	);
});
