	/**		Selfads - Featured Items		**/



	var total_items = 1, visible_item = 1, busy = false, timer, timeout = 10000000;

	var coming_total_items = 1, coming_visible_item = 1, coming_busy = false, coming_timer, coming_timeout = 8000;



	function slide_featured(nr) {

		

		if (typeof nr == "undefined") {

			nr = visible_item + 1;

			nr = nr > total_items ? 1 : nr;

		}

		

		if (busy || visible_item == nr) {

	 		return;	

		}

		

		busy = true;

		

		$(".nav a")

			.removeClass('active')

			.filter("a[rel=" + nr + "]")

			.addClass('active');

		var ni = $(".nav a")

			.filter("a[rel=" + nr + "]")

			.attr('id');

		niAr = ni.split("-");

		//alert(niAr[0]);

		var curr = $("#featured li:visible"); 

		

		curr.fadeOut(300,function(){

			curr.css("z-index", 10).hide();

			if(niAr[1]>724)

			{

				$("#rightColumn3").removeClass('nopanorama').addClass('panorama');

			}

			else if(niAr[1]<=724)

			{

				$("#rightColumn3").removeClass('panorama').addClass('nopanorama');

			}

			

			$('#content').fadeOut(300,function(){

					$(this).hide();						

				});

			$("#featured li:eq(" + (nr - 1) + ")").fadeIn(400,function(){

				$('#content').load('includes/loadImageContent.php?id='+niAr[0],function () {

					$(this).fadeIn(300,function(){

					$(this).show();						

					});														

					check_position( nr );														

					visible_item = nr;

					$(this).css("z-index", 11);

					busy = false;

				});

			});

			

		});

		

	}



	function check_position(newId)

		{

			var mt = $('#slider ul').css('marginTop');

			

					var pp = (parseInt(mt)/(-144)) + 1;

					var q = 0;

					if((newId/9)<=1)

					{

						q = 1;

					}

					else if((newId/9)>1 && (newId/9)<=2)

					{

						q = 2;

					}

					else if((newId/9)>2 && (newId/9)<=3)

					{

						q = 3;

					} 

					else if((newId/9)>3 && (newId/9)<=4)

					{

						q = 4;

					} 

					

					if(pp>q)

					{

						for(var sl=0; sl<(pp - q); sl++)

						{

							$('#prevBtn').trigger('click');

						}

					}

					else if(pp<q)

					{

						for(var sl=0; sl<(q - pp); sl++)

						{

							$('#nextBtn').trigger('click');

						}

					}

				$("#number").html(newId);

				curNum = newId;

		}

	

	function next_image()

		{

			var total = parseInt($("#total").html());

			var curId = parseInt($("#number").html());

				

				if(curId==total)

				{

					var newId = 1;

				}

				else

				{

					var newId = curId + 1;

				}

				slide_featured( newId );

				//if($("#ajaxLoadBig_"+(newId - 1)).attr('complete'))

//				{

//					slide_featured( newId );

//				}

//				else

//				{

//					return;

//				}

				

		

		}

		

		function prev_image()

		{

			var total = parseInt($("#total").html());

			var curId = parseInt($("#number").html());

				

				if(curId==1)

				{

					var newId = total;

				}

				else

				{

					var newId = curId - 1;

				}

				slide_featured( newId );

				//if($("#ajaxLoadBig_"+(newId - 1)).attr('complete'))

//				{

//					slide_featured( newId );

//				}

//				else

//				{

//					return;

//				}

		}

		var bigImage =new Array();

		function slide(count)

		{

			var len = $("span.transSliderWrap").length;

			if(count < len)

			{ 

				//$(".layer_"+count+"").addLoader()

				//var jNode=$('<img src="images/test.gif" />').appendTo(".layer_"+count+"");

				//$(".layer_"+count+"").css('background','url(images/loading.gif)');

				id = $(".big_image_"+count).attr('id');

				idAr = id.split("-");

						$(".big_image_"+count).html('<a href="#" class="featured_link" ></a><img alt="'+idAr[1]+'" src="'+idAr[0]+'" width="'+idAr[2]+'" id="ajaxLoadBig_'+ count +'" style="display:none;" title="'+ idAr[1] +'" /><div class="png"></div>');

						$("#ajaxLoadBig_"+count+"").delay(1000).load(function () {

								//$(".layer_"+count+"").animate({

//									"left": "+=39px",

//									"width":  "toggle"

//								 },2000, function() {

//									 $(this).hide(); 

//								});

							$("#ajaxLoadBig_"+count+"").fadeIn(2000,function(){

								//change opacity of small thumb to 1

							    //$('.ajaxLoad_'+ count +'').fadeTo(600,1,function(){	$(".layer_"+count+"").fadeOut('slow');			});	

								 //$('img .ajaxLoad_'+ count +'').bind('click');

								 var nextcnt = count + 1;

				   				 slide(nextcnt);

							});///allow large iamge to show

							

						});

			}

			else

			{

				return;	

			}

		}

	

	jQuery(function(){

		//slide(0);

					

		var curNum = $("#number").html();

		/**		Selfads - Assign click and Show first		**/

		$(".nav a")

			.hover(function() {

				var curNum = $("#number").html();

				$("#number").html(this.rel).css('color','#333333');

			}).mouseout(function() {$("#number").html(curNum).css('color','#999999');});

			

		$(".nav img")

			.click(function() {

				var relid = $(this).parent().parent().attr('rel');

				slide_featured( relid);

				$("#number").html(relid);

				curNum = relid;

			});

			

			$("#prevBtnC")

			.click(function() {

				prev_image();				

			});

			

			$("#nextBtnC")

			.click(function() {

				next_image();			

			});

			

			$("#featured li").each(function(i){

				  $(this).click(function() {

					  next_image();	  

				  });

			 });

			

		//$("#featured li:eq(0)").load(function () {

//			.css("z-index", 12).fadeIn(1000);

//			

//		});

		

		var Inimagewidth = $("#featured li:eq(0) img").attr('width');

					if(Inimagewidth>724)

					{

						$("#rightColumn3").addClass('panorama').removeClass('nopanorama');

					}

					else if(Inimagewidth<=724)

					{

						$("#rightColumn3").addClass('nopanorama').removeClass('panorama');

					}	

					

		

		

		$("#featured li:eq(0)")

			.css("z-index", 12).delay(2000)

			.fadeIn("slow",function(){

					var imagewidth = $(this).find("img").attr('width');

					if(imagewidth>724)

					{

						$("#rightColumn3").addClass('panorama').removeClass('nopanorama');

					}

					else if(imagewidth<=724)

					{

						$("#rightColumn3").addClass('nopanorama').removeClass('panorama');

						

					}	

					$("#content").fadeIn("slow");

				});

		

		

		total_items = $("#featured li").length;

		

	});
