function get_sec_article_height(){
	var sl_h,sr_h;
	sl_h=$("li.sec-left-article").height();
	sr_h=$("li.sec-right-article").height();
	max_height=Math.max(sl_h,sr_h);
	$("li.sec-left-article").height(max_height);
	$("li.sec-right-article").height(max_height);
}
function toggle_full_gallery(flag)
{
if (flag!=1)
{
var nr=$("dl.gallery-item").length;
if (nr>24)
{
	$("#gallery-1").addClass("show-less");
	$("#gallery-1").after('<a href="javascript:toggle_full_gallery(1)" class="show-full-gallery-trigger">Toata galeria foto &dArr;</a>');
}
}
else
{
	$("#gallery-1").fadeOut("fast").fadeIn("medium").removeClass("show-less");
	$(".show-full-gallery-trigger").hide();
}
}
function changeLocation(menuObj)
{
   var i = menuObj.selectedIndex;

   if(i > 0)
   {
      window.location = 'http://www.autoiq.ro/top/'+menuObj.options[i].value;
   }
}


$(document).ready(function() {
	
	 if (!document.getElementsByTagName) return false;
	  var links = document.getElementsByTagName("a");
	  if (links.length == 0) return false;
	  for (var i = 0; i < links.length; i++) {
	    var relation = links[i].getAttribute("rel");
	    if (relation == "external") {
	      links[i].onclick = function() {
	        return !window.open(this.href);
	      }
	    }     
	  }
	
	// replace these default settings with your own
	$.querySort = {
		path_to_template: 'http://www.autoiq.ro/wp-content/themes/mi-magazine/ajax/',
		number_of_posts: 3,
		default_category: $("#top-filter").html()
	}

	// do the initial load.
	$("#querySort").load($.querySort.path_to_template + 'top.php' + '?query=showposts%3D' + 
			$.querySort.number_of_posts + '%26category_name%3D' + $.querySort.default_category + '%26orderby%3Dmeta_value_num%26meta_key%3Dcoeficient_iq%26order%3DDESC');

	//functions for the sorter
	$("#top-menu a").click(function(){
		$("#top-menu").hide();
		$("#top-filter").removeClass("open");
		var thecat = $(this).attr("id");
		$("#top-filter").html(thecat);
		if (thecat == 'general') {
			thecat='';
			var query = '?query=showposts%3D' + $.querySort.number_of_posts + '%26category_name%3D' + thecat + '%26orderby%3Dmeta_value_num%26meta_key%3Dcoeficient_iq%26order%3DDESC';
		} else {
			var query = '?query=showposts%3D' + $.querySort.number_of_posts + '%26category_name%3D' + thecat + '%26orderby%3Dmeta_value_num%26meta_key%3Dcoeficient_iq%26order%3DDESC';
		}
		$("#querySort").animate({opacity: 0}, function() {
			$("#querySort").load($.querySort.path_to_template + 'top.php' + query, function() {
				height = $("#queryContainer").height() + 'px';
				$("#querySort").animate({opacity: 1, height:height});
			});
		});
		return false;
	});
	
	
$("#tab1-button").click(
	function(){
		$(".tab1-list").fadeIn("medium");
		$(this).parent().removeClass("inactive").addClass("active");
		
		$(".tab2-list").hide();
		$("#tab2-button").parent().removeClass("active").addClass("inactive");
		return false;
});
$("#tab2-button").click(
		function(){
			$(".tab2-list").fadeIn("medium");
			$(this).parent().removeClass("inactive").addClass("active");
			
			$(".tab1-list").hide();
			$("#tab1-button").parent().removeClass("active").addClass("inactive");
			return false;
	});

	
		$("#top-filter").click(
				function(){
				if ($("#top-filter").hasClass("open")=='true')
				{
						$("#top-menu").hide();
						$("#top-filter").removeClass("open");
						return false;	
				}
				else
				{
						$("#top-menu").show();
						$("#top-filter").addClass("open");
						return false;
					
				}	
			});

		$('body').click(function() {
				$("#top-menu").hide();
				$("#top-filter").removeClass("open");
			});

$(".show-full-gallery-trigger").click(function(){
	$("#gallery-1").fadeOut().removeClass("show-less").fadeIn();
	$(this).hide();
});

get_sec_article_height();
toggle_full_gallery(0);		

$('.more').live("click",function()
		{
		var query = '?query=showposts%3D' + $.querySort.number_of_posts + '%26category_name%3D' + $.querySort.default_category + '%26orderby%3Dmeta_value_num%26meta_key%3Dcoeficient_iq%26order%3DDESC';
		var ID = $(this).attr("id");
		var top_id = $(".top-full").attr("id");
		var clasa = top_id.substring(0,top_id.indexOf(" "));
		var order = top_id.substring(top_id.indexOf(" ")+1);
		if(ID)
		{
		$("#more"+ID).html('<img style="margin-bottom:10px;margin-left:333px;" src="'+$.querySort.path_to_template+'ajax-loader.gif" />');

		$.ajax({
			type: "POST",
			url: $.querySort.path_to_template+"/top_get_more.php",
			data: "offset="+ ID + "&order=" + order + "&clasa=" + clasa,
			cache: false,
			success: function(html){
				$("ul.top-full").append(html);
				$("#more"+ID).remove(); // removing old more button
			}
		});
		}
		else
		{
		$(".morebox").html('The End');// no results
		}

		return false;
		});


// Slider


$("#4x4.hof-content").show();
$(".slider-link").hover(
	function(){
		$(".slider-clasa li").removeClass("selected");
		$(this).parent("li").addClass("selected");
		var clasa=$(this).attr("title");
		clasa="#"+clasa+".hof-content";
		$(".hof-content").fadeOut();
		$("#"+clasa+".hof-content").fadeIn("medium");
		return false;
	},
	function(){
		return false;
	}
	);
$(".slider-link").click(
		function(){
			$(this).addClass("selected");
			return false;
		});

$(".top-full li").click(function(){
	window.location=$(this).find("a").attr("href");return false;
});

});




