// Allows console to alert in IE
if( !console ) { var console = { log: function(msg) {  } } }

$().ready(function() {

	$('table.layoutTable').animate({ height: "show", opacity: "show" }, 3000);
	$('table.layoutTable td').slideDown('fast')

	// get all filters and set mouseover
	$(".filter a").mouseover( function(){
		if($(this).parent()[0].className == 'exception'){
			$(this).parent().css('background', 'none');
			$(this).css('text-decoration', 'none');
		}
		else if($(this).parent()[0].className == ''){
		//highlight active 
		$(this).parent().addClass("Active");
		// get rel attribute
		if( $(this).attr("rel") ) {
			var articleIDs = $(this).attr("rel").split(' ');	
			$().find(".resultItemList").each(function(i,ele){
				$(articleIDs).each( function(i, theID ){
				//console.log("theID: "+ theID);
					if( ele.id == theID ) {
						if(ele.rowIndex == "1"){ $(ele).addClass("Activetoprow").removeClass("toprow");}
						else { $(ele).addClass("Active"); }
					}
				});
			});
		}
		}//else
	});//mouseover
	$(".filter a").mouseout( function(){
		$(this).parent().removeClass("Active");
		$().find(".resultItemList").each(function(i,ele){
			if(ele.rowIndex == "1"){ $(ele).addClass("toprow").removeClass("Activetoprow"); }
			$(ele).removeClass("Active");
		});
	});//mouseout
		
	$(".resultItemList").mouseover( function(){
		//highlight mouseover div
		$(this).addClass("Active");

		//get div id
		var itemID = $(this).attr("id");
			$(this).each(function(i, arr){
				$().find(".filter a").each(function(j,ele){
					var articleIDs = ele.rel.split(' ');	
					$(articleIDs).each( function(k, relID) {
						if(arr.id == relID) {
							if(arr.rowIndex == "1"){ $(arr).addClass("Activetoprow").removeClass("toprow").removeClass("Active"); }
							$(ele).parent().addClass("Active");
						}
					});
				});
			});
			
	});//mouseover

	$(".resultItemList").mouseout( function(){
		$(this).removeClass("Active");
		$().find(".filter a").each(function(j,ele){
			$('tr:eq(1)').addClass("toprow").removeClass("Activetoprow");
			$(ele).parent().removeClass("Active");
		});
	});//mouseout

	$("dd.exception li a").mouseover( function(){
		$(this).parent().append('<div class="remove-filter"></div>');
		$('.remove-filter').css('display', 'block');
	});//mouseover

	$("dd.exception li a").mouseout( function(){
		$('.remove-filter').remove();
	});//mouseout

	//More Function Affect
		var h = $('.dimensionNavContainer').height();
	$("#listAreaCol1 .toggleListShow").click(function () {
		$('.column').height(h);
		$('#listAreaCol1').addClass("groupExpended")
		$('.sub-menuCol1').css('display', 'block');
		$("#listAreaCol1 .toggleListShow").hide()
		$("#listAreaCol1 .toggleListHide").show();
		return false;
	});
	$("#listAreaCol1 .toggleListHide").click(function () {
		$('.sub-menuCol1').css('display', 'none');
		$("#listAreaCol1 .toggleListShow").show()
		$("#listAreaCol1 .toggleListHide").hide();
		return false;
	});

	$('#listAreaCol1 a').click(function(){
		var locationName = $(this).attr('title');
		var url = $(this).attr('href');
		$('#listAreaCol1').css('display', 'none');
		$('#filterListSelectedCol1').css('display', '');
		$("<li><button class='removeBtn'><img src='/static/media_structure/common/img/productslist.close.gif' /></button><a href='"+url+"'>"+locationName+"</a></li>").insertBefore("#chooseAnotherCol1");
			var li_length = $('#filterListSelectedCol1 ul li').length;
			if(li_length >= 5) {
				$('.group').hide();
			}
			if((li_length >= 3) && $('#filterListSelectedCol1 ul').parent()[0].className == 'single'){
				$('#filterListSelectedCol1 ul li:eq(0)').remove();
			}
			
		$('#filterListSelectedCol1 .filterHide').hide();
		$('#filterListSelectedCol1 .filterShowExtended').show();
			$('.removeBtn').click(function () {
		     $(this).parent().remove();
	 			if(li_length < 5) {
				$('.group').show();
				}
		    });
	});
	$('#filterListSelectedCol1 .filterShowExtended').click(function(event){
		$('#listAreaCol1').css('display', '');
		$('#listAreaCol1').css('position', 'absolute');
		$('#filterListSelectedCol1 .filterShowExtended').hide();
		$('#filterListSelectedCol1 .filterHide').show();
	});
	$('#filterListSelectedCol1 .filterHide').click(function(event){
		$('#listAreaCol1').css('display', 'none');
		$('#filterListSelectedCol1 .filterHide').hide();
		$('#filterListSelectedCol1 .filterShowExtended').show();
	});
	
	//
	
	$("#listAreaCol2 .toggleListShow").click(function () {
			$('.column').height(h);
			$('#listAreaCol2').addClass("groupExpended")
			$('.sub-menuCol2').css('display', 'block');
			$("#listAreaCol2 .toggleListShow").hide()
			$("#listAreaCol2 .toggleListHide").show();
			return false;
		});
		$("#listAreaCol2 .toggleListHide").click(function () {
			$('.sub-menuCol2').css('display', 'none');
			$("#listAreaCol2 .toggleListShow").show()
			$("#listAreaCol2 .toggleListHide").hide();
			return false;
		});
	
		$('#listAreaCol2 a').click(function(){
			var locationName = $(this).attr('title');
			var url = $(this).attr('href');
			$('#listAreaCol2').css('display', 'none');
			$('#filterListSelectedCol2').css('display', '');
			$("<li><button class='removeBtn'><img src='/static/media_structure/common/img/productslist.close.gif' /></button><a href='"+url+"'>"+locationName+"</a></li>").insertBefore("#chooseAnotherCol2");
				var li_length = $('#filterListSelectedCol2 ul li').length;
				if(li_length >= 5) {
					$('.group').hide();
				}
				if((li_length >= 3) && $('#filterListSelectedCol2 ul').parent()[0].className == 'single'){
					$('#filterListSelectedCol2 ul li:eq(0)').remove();
				}
				
			$('#filterListSelectedCol2 .filterHide').hide();
			$('#filterListSelectedCol2 .filterShowExtended').show();
				$('.removeBtn').click(function () {
			     $(this).parent().remove();
		 			if(li_length < 5) {
					$('.group').show();
					}
			    });
		});
		$('#filterListSelectedCol2 .filterShowExtended').click(function(event){
			$('#listAreaCol2').css('display', '');
			$('#listAreaCol2').css('position', 'absolute');
			$('#filterListSelectedCol2 .filterShowExtended').hide();
			$('#filterListSelectedCol2 .filterHide').show();
		});
		$('#filterListSelectedCol2 .filterHide').click(function(event){
			$('#listAreaCol2').css('display', 'none');
			$('#filterListSelectedCol2 .filterHide').hide();
			$('#filterListSelectedCol2 .filterShowExtended').show();
	});
	
	
	//
	
		
		$("#listAreaCol3 .toggleListShow").click(function () {
				$('.column').height(h);
				$('#listAreaCol3').addClass("groupExpended")
				$('.sub-menuCol3').css('display', 'block');
				$("#listAreaCol3 .toggleListShow").hide()
				$("#listAreaCol3 .toggleListHide").show();
				return false;
			});
			$("#listAreaCol3 .toggleListHide").click(function () {
				$('.sub-menuCol3').css('display', 'none');
				$("#listAreaCol3 .toggleListShow").show()
				$("#listAreaCol3 .toggleListHide").hide();
				return false;
			});
		
			$('#listAreaCol3 a').click(function(){
				var locationName = $(this).attr('title');
				var url = $(this).attr('href');
				$('#listAreaCol3').css('display', 'none');
				$('#filterListSelectedCol3').css('display', '');
				$("<li><button class='removeBtn'><img src='/static/media_structure/common/img/productslist.close.gif' /></button><a href='"+url+"'>"+locationName+"</a></li>").insertBefore("#chooseAnotherCol3");
					var li_length = $('#filterListSelectedCol3 ul li').length;
					if(li_length >= 5) {
						$('.group').hide();
					}
					if((li_length >= 3) && $('#filterListSelectedCol3 ul').parent()[0].className == 'single'){
						$('#filterListSelectedCol3 ul li:eq(0)').remove();
					}
					
				$('#filterListSelectedCol3 .filterHide').hide();
				$('#filterListSelectedCol3 .filterShowExtended').show();
					$('.removeBtn').click(function () {
				     $(this).parent().remove();
			 			if(li_length < 5) {
						$('.group').show();
						}
				    });
			});
			$('#filterListSelectedCol3 .filterShowExtended').click(function(event){
				$('#listAreaCol3').css('display', '');
				$('#listAreaCol3').css('position', 'absolute');
				$('#filterListSelectedCol3 .filterShowExtended').hide();
				$('#filterListSelectedCol3 .filterHide').show();
			});
			$('#filterListSelectedCol3 .filterHide').click(function(event){
				$('#listAreaCol3').css('display', 'none');
				$('#filterListSelectedCol3 .filterHide').hide();
				$('#filterListSelectedCol3 .filterShowExtended').show();
		});
		
		
		$("#listAreaCol4 .toggleListShow").click(function () {

				$('.column').height(h);

				$('#listAreaCol4').addClass("groupExpended")

				$('.sub-menuCol4').css('display', 'block');

				$("#listAreaCol4 .toggleListShow").hide()

				$("#listAreaCol4 .toggleListHide").show();

				return false;

			});

			$("#listAreaCol4 .toggleListHide").click(function () {

				$('.sub-menuCol4').css('display', 'none');

				$("#listAreaCol4 .toggleListShow").show()

				$("#listAreaCol4 .toggleListHide").hide();

				return false;

			});

		

			$('#listAreaCol4 a').click(function(){

				var locationName = $(this).attr('title');

				var url = $(this).attr('href');

				$('#listAreaCol4').css('display', 'none');

				$('#filterListSelectedCol4').css('display', '');

				$("<li><button class='removeBtn'><img src='/static/media_structure/common/img/productslist.close.gif' /></button><a href='"+url+"'>"+locationName+"</a></li>").insertBefore("#chooseAnotherCol3");

					var li_length = $('#filterListSelectedCol4 ul li').length;

					if(li_length >= 5) {

						$('.group').hide();

					}

					if((li_length >= 3) && $('#filterListSelectedCol4 ul').parent()[0].className == 'single'){

						$('#filterListSelectedCol4 ul li:eq(0)').remove();

					}

					

				$('#filterListSelectedCol4 .filterHide').hide();

				$('#filterListSelectedCol4 .filterShowExtended').show();

					$('.removeBtn').click(function () {

				     $(this).parent().remove();

			 			if(li_length < 5) {

						$('.group').show();

						}

				    });

			});

			$('#filterListSelectedCol4 .filterShowExtended').click(function(event){

				$('#listAreaCol4').css('display', '');

				$('#listAreaCol4').css('position', 'absolute');

				$('#filterListSelectedCol4 .filterShowExtended').hide();

				$('#filterListSelectedCol4 .filterHide').show();

			});

			$('#filterListSelectedCol4 .filterHide').click(function(event){

				$('#listAreaCol4').css('display', 'none');

				$('#filterListSelectedCol4 .filterHide').hide();

				$('#filterListSelectedCol4 .filterShowExtended').show();

		});
		
		
	//

	$("#filterListLocation .toggleListShow").click(function () {
		//var h = $('.dimensionNavContainer').height();
		$('.column').height(h);
		$('#filterListLocation').addClass("groupExpended")
		$('.sub-menuCol2').css('display', 'block');
		$("#filterListLocation .toggleListShow").hide()
		$("#filterListLocation .toggleListHide").show();
		return false;
	});
	$("#filterListLocation .toggleListHide").click(function () {
		$('.sub-menuCol2').css('display', 'none');
		$("#filterListLocation .toggleListShow").show()
		$("#filterListLocation .toggleListHide").hide();
		return false;
	});
	$('#filterListLocation a').click(function(){
		var locationName = $(this).attr('title');
		var url = $(this).attr('href');
		$('#filterListLocation').css('display', 'none');
		$('#filterListSelectedCol2').css('display', '');
		$("<li><button class='removeBtn'><img src='/static/media_structure/common/img/productslist.close.gif' /></button><a href='"+url+"'>"+locationName+"</a></li>").insertBefore("#chooseAnotherCol2");
			var li_length = $('#filterListSelectedCol2 ul li').length;
			if(li_length >= 5) {
				$('.country').hide();
			}
		$('#filterListSelectedCol2 .filterHide').hide();
		$('#filterListSelectedCol2 .filterShowExtended').show();
			$('.removeBtn').click(function () {
			//console.log(this);
		     $(this).parent().remove();
				var li_length = $('#filterListSelectedCol2 ul li').length;
	 			if(li_length < 5) {
				$('.country').show();
				}
		    });
	});
	$('#filterListSelectedCol2 .filterShowExtended').click(function(event){
		$('#filterListLocation').css('display', '');
		$('#filterListLocation').css('position', 'absolute');
		$('#filterListSelectedCol2 .filterShowExtended').hide();
		$('#filterListSelectedCol2 .filterHide').show();
	});
	$('#filterListSelectedCol2 .filterHide').click(function(event){
		$('#filterListLocation').css('display', 'none');
		$('#filterListSelectedCol2 .filterHide').hide();
		$('#filterListSelectedCol2 .filterShowExtended').show();
	});
	//end

// end
});//main data

