// JavaScript Document

var actual = 0;
var vec= new Array(); // vector de post
function buscaindexanclaactual(){
	iden = document.location.hash.replace("#",""); 
	if(document.location.hash!="")
		for(i=0;i<vec.length;i++)
		{
			var valor=vec[i];
			if(valor==iden){
				return i;
			}
		}
	return 0;
}
function buscaindex(valor)
{
	for(i=0;i<vec.length;i++)
		{
			var val=vec[i];
			if(val==valor){
				return i;
			}
	}
	return 0;
}

$(document).ready(function(){
	//$("#arrastra_izq").makeFloat({x:"current",y:"current"});
	//$("#arrastra_der").makeFloat({x:"current",y:"current"});
	//alert("sss");

	
	$('.menu-item').click(function() {
		estado=$(this).children('.sub-menu').css("display");
		$(this).children('.sub-menu').toggle('slow');
		return false;
	});
	$('.menu-item  li a').click(function() {
		
	});
	$('.sub-menu  li a').click(function() {
		var cssObj = {
		  'background-color' : '#ddf906',
		  'color' : '#666'
    	}
		var cssObj2 = {
		  'background-color' : '#FFF',
		  'color' : '#666'
    	}
		$('.sub-menu  li a').css(cssObj2);
		$(this).css(cssObj);
	});
	$('#menu-ppal a[href*=#]').click(function() {
		
		var cssObj = {
		  'background-color' : '#ddf906',
		  'color' : '#666'
    	}
		var cssObj2 = {
		  'background-color' : '#FFF',
		  'color' : '#000'
    	}
		var cssObj3 = {
		  'background-color' : '#FFF',
		  'color' : '#666'
    	}
		$('#menu-ppal a[href*=#]').css(cssObj2);
		$('.sub-menu  a[href*=#]').css(cssObj3);
		$(this).css(cssObj);
		
		var elementClick = $(this).attr("href")
		destination = $(elementClick).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
		return false;
		
  	});
	$('a[href*=#][class=carusel]').click(function() {
		var elementClick = $(this).attr("href")
		destination = $(elementClick).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
		return false;
		
  	});
	
	
	$('.linkscroll a[href*=#]').click(function() {
		var divOffset = $('#contenedor').offset().top;
		var $target = $(this.hash);
		actual=buscaindex(this.hash.replace("#",""));
		var pOffset = $('#contenedor div:#'+this.hash).offset().top;
		
		var pScroll = pOffset - divOffset;
		 $('#contenedor').animate({scrollTop: '+=' + pScroll + 'px'}, 1000);
  	});
	
	$(".noticias2_link").fancyZoom();
});
function cargarNoticia(idpost)
{
	// clear the-posts content
    jQuery("#noticias2").children().remove();
	jQuery.ajax({
      type: 'POST',
      url: 'http://real.com.co/ajax-realmusic.php',
      data: {
        'action': 'mfields_show_post', // this must be the same with your ajax function name
        'p': idpost 
      },
      success: function(data)
      {
		 //alert(data);
		 jQuery("#zoom_content").append(data);
      },
      error: function(MLHttpRequest, textStatus, errorThrown)
      {
      },
      complete: function(XMLHttpRequest, textStatus)
      {
        // hide the loading image
        // hideWaitingImage();
      },
      dataType: 'html'
    });
}


function loadPostsFromCat(category)
{
   // clear the-posts content
    jQuery("#the-posts").children().remove();
    // show the loading image here
    // showWaitingImage();
    jQuery.ajax({
      type: 'POST',
      url: 'http://real.com.co/wp-admin/admin-ajax.php',
      data: {
        'action': 'my_get_posts', // this must be the same with your ajax function name
        'cat': category 
      },
      success: function(data, textStatus, XMLHttpRequest)
      {
        for (var entry in data)
        {        
          // get post's attributes
          var titulo = data[entry].title;
          var link = data[entry].link;
         // append new post into the-posts, with permalink
          jQuery("#some-list").append("<li><a href='" + link + "'>" + titulo + "</a></li>");
        }
      },
      error: function(MLHttpRequest, textStatus, errorThrown)
      {
      },
      complete: function(XMLHttpRequest, textStatus)
      {
        // hide the loading image
        // hideWaitingImage();
      },
      dataType: 'json'
    });
  }
  
function loadPosts(idpost)
{
   // clear the-posts content
   jQuery("#novedades").fadeOut('slow',function(){
    jQuery("#novedades").children().remove();
	});
    // show the loading image here
    // showWaitingImage();
    jQuery.ajax({
      type: 'POST',
      url: 'http://real.com.co/ajax-realmusic.php',
      data: {
        'action': 'mfields_show_post', // this must be the same with your ajax function name
        'p': idpost 
      },
      success: function(data)
      {
		 //alert(data);
		 jQuery("#novedades").append(data);
		 jQuery("#novedades").fadeIn('slow');
      },
      error: function(MLHttpRequest, textStatus, errorThrown)
      {
      },
      complete: function(XMLHttpRequest, textStatus)
      {
        // hide the loading image
        // hideWaitingImage();
      },
      dataType: 'html'
    });
  }  
  // do the same with other links but change the cat ID
