﻿function get_results(ttt,aaa,seepage)
{
	$("#mp1").hide();
	$("#mp2").hide();
	$("#mp3").hide();
	$("#mp4").hide();
	$("#mp5").hide();
	$("#mp6").hide();
	$(".pglink").hide();

	//var var_highres=read_lang_var(1,v_languagename);
	//var var_lowres=read_lang_var(2,v_languagename);
	var var_highres=media_v1;
	var var_lowres=media_v2;

	for (jjj=1;jjj <= 6;jjj++)
	{
		$("#mp" + jjj).html("");
		$("#pix" + jjj).html("");
		$("#piy" + jjj).html("");
		$("#desc" + jjj).html("");
	}
	if (aaa==1)
	{
		v_category=document.getElementById('category').options[document.getElementById('category').selectedIndex].value;
	}
	else if (aaa==2)
	{
		v_category=ttt.options[ttt.selectedIndex].value;
	}
	else
	{
		v_category=document.getElementById('category').options[document.getElementById('category').selectedIndex].value;
	}
	//alert(v_category);
	var total_imgs=0;
	var item_in_page=0;
	var total_pages=0;
	$.ajax({
		type: "GET",
		url: "../../cms/htmlxml/media/media_" + v_languagename + ".xml",
		dataType: "xml",
		success: function(xml) {
		  $(xml).find('page').each(function(){
		  if ($(this).attr('id')=="photolibrary")
		  {
			$(this).find('item').each(function(){
				var xid = $(this).attr('id');
				var xtitle = $(this).attr('title');
				var xbrand = $(this).attr('brand');
				var xcategory = $(this).attr('category');
				var category_valid=0;
				if (v_category==0)
				{
					category_valid=1;
				}
				else
				{
					//if (xcategory==acategory[v_category]) category_valid=1;
					if (xcategory==v_category) category_valid=1;
				}
				if (category_valid==1)
				{
					total_imgs=total_imgs + 1;
					if (total_imgs==1) total_pages=1;
					item_in_page=item_in_page + 1;
					if (item_in_page > 6)
					{
						item_in_page=1;
						total_pages=total_pages + 1;
					}
					if (total_pages==seepage)
					{
						$("#mp" + item_in_page).show();
						//$("#pti" + item_in_page).html("");
						$("#desc" + item_in_page).html(xtitle + "<BR><BR>");
						$(this).find('textnode').each(function(){
							var xid2 = $(this).attr('id');
							var thetext = $(this).text();
							$("#dialog" + item_in_page).dialog({ title: '<font style="font-family:Times New Roman,sans-serif,arial,helvetica;font-weight:normal;font-size:20px;color: #EEEEEE;">' + xbrand + '</font>' });
							xbrand="";

							if (xid2=="imagethumbnail")
								$("#mp" + item_in_page).html('<a href="#"><img src="' + urlreplace + imgpath_replace(thetext) + '" border=0 hspace="0" vspace="0" alt="' + xtitle + '"></a>');
							else if (xid2=="image")
							{
								what_width=getImgSize(urlreplace + imgpath_replace(thetext),0);
								what_height=getImgSize(urlreplace + imgpath_replace(thetext),1);
								what_width2="";
								what_height2="";
								if (what_width > what_height)
								{
									what_width2="width=300";
									what_height2="";
								}
								else if (what_width < what_height)
								{
									what_width2="";
									what_height2="height=200";
								}
								else
								{
									what_width2="";
									what_height2="height=200";
								}
								$("#pix" + item_in_page).html("<img src=" + urlreplace + imgpath_replace(thetext) + " border=0 " + what_width2 + " " + what_height2 + " hspace=0 vspace=0 alt='" + xtitle + "'>");
							}
							else if (xid2=="highres")
								$("#piy" + item_in_page).html("<a href=" + urlreplace + imgpath_replace(thetext) + " class=contentlink target=_blank>" + var_highres + " <img src=../../images_new/arrow3.gif border=0></a><BR>");
							else if (xid2=="lowres")
								$("#piy" + item_in_page).append("<a href=" + urlreplace + imgpath_replace(thetext) + " class=contentlink target=_blank>" + var_lowres + " <img src=../../images_new/arrow3.gif border=0></a><BR><img src=../../images_new/shim.gif width=1 height=100 border=0>");
							else if (xid2=="description")
								$("#desc" + item_in_page).append(thetext + "<BR><BR>");
						});
					}
				}
			});
			if (total_pages > 0)
			{
				for (iii=1;iii <= total_pages;iii++)
				{
					if (seepage==iii)
					{
						//tpages=tpages + "<b>" + seepage + "</b> &nbsp;";
						$("#go" + iii).show();
						$("#go" + iii).css({"color":"#47451a"});;
					}
					else
					{
						//tpages=tpages + '<a href="photolibrary.html?id=' + iii + '" class=pglink>' + iii + '</a> &nbsp;';
						$("#go" + iii).show();
						$("#go" + iii).css({"color":"#9a9a9a"});;
					}
				}
			}
			//$("#dialog1").attr("title", "your new title");
		  }
		  });
		}
	});
}

$(document).ready(function(){
  get_results("",0,1);

  $("select.category").change(function(){
	get_results(this,2,1);
  });


	$(function(){
		$('#dialog1').dialog({
			autoOpen: false,
			width: 600,
			height: 340,
			resizable: false,
			modal: true
		});
		$('#dialog2').dialog({
			autoOpen: false,
			width: 600,
			height: 340,
			resizable: false,
			modal: true
		});
		$('#dialog3').dialog({
			autoOpen: false,
			width: 600,
			height: 340,
			resizable: false,
			modal: true
		});
		$('#dialog4').dialog({
			autoOpen: false,
			width: 600,
			height: 340,
			resizable: false,
			modal: true
		});
		$('#dialog5').dialog({
			autoOpen: false,
			width: 600,
			height: 340,
			resizable: false,
			modal: true
		});
		$('#dialog6').dialog({
			autoOpen: false,
			width: 600,
			height: 340,
			resizable: false,
			modal: true
		});
		
		$('#mp1').click(function(){
			$('#dialog1').dialog('open');
			return false;
		});
		$('#mp2').click(function(){
			$('#dialog2').dialog('open');
			return false;
		});
		$('#mp3').click(function(){
			$('#dialog3').dialog('open');
			return false;
		});
		$('#mp4').click(function(){
			$('#dialog4').dialog('open');
			return false;
		});
		$('#mp5').click(function(){
			$('#dialog5').dialog('open');
			return false;
		});
		$('#mp6').click(function(){
			$('#dialog6').dialog('open');
			return false;
		});
	});
});

