$(function () {
     $("#subNav div").appendTo("#subNav");
    // Pager thing
    var list = 12;
    count = 0;
    var ul = null

	//var column = getParameterByName( column );
	//alert(column);






    
    $("#slider").after('<ul id="listnav"></ul>');
    var total = $("#subNav #subNav3 li").size();
    //alert(total);




    $("#subNav #subNav3 li").each(function(i){
//        console.log(count+':'+i);
        if ((i - (count * list)) % list == 0 ) {
            count++;
			
			

          //  console.log("Creating list "+count);
            $("#subNav #sliderW").append("<ul class='list' id='list"+count+"'></ul>");

            if (total > list) {
                $("#listnav").append('<li class="slideto">'+count+'</li>');
            }
        }
        $(this).remove().appendTo('#list'+count);

        //$("#list"+count).append($(this).html());
        //$(this).remove();
    
    });




    $("li.slideto").click(function(){
        pos = ($(this).html());
		newMargin = -(165 * (pos -1)) + 'px';
		$("#sliderW").animate( { marginLeft: newMargin}, 1000);
    });



	new_count=1;
	$("#subNav #subNav3 li").each(function(i){
		
			if ($(this).hasClass("current") )
			{
				
				//$('code, li.current') 
				//$subNav.find('li[class='+$current+']').css('color','blue');
				//alert($('#subNav #subNav3 li').attr('class'));
				//position = new_count % list;
				position = 1;
				if ( new_count > 12 )
				{
					position = (new_count / list)+ 1;
					position = parseInt(position) ;
				}
				//alert("This is the column :" + position + " This is the count: " + new_count);
				//console.log('This is: '+$(this).text());

				slideColumn(position);
			}
			new_count++;

	});


});


function slideColumn(column){
	newMargin = -(165 * (column -1)) + 'px';
	//$("#sliderW").animate( { marginLeft: newMargin}, 1000);
	$("#sliderW").css('marginLeft', newMargin);
}

/*function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}*/



