/**
 * @copyright Tercio Web Studio (tercio.ru) 2008
 * @author Leha Stratan (ls@tercio.ru)
 * 
 * да уж...
 */

$(document).ready(main);

function main(){
	
	DetectCurrentMenu();
	
	var suffix = ""
	

	
	$("div#scrollable-photogallery a").each(function(index, domEl){

		var base = $(this).find("img").attr("src");
		if (base == null || base == "") {
			base = "";
		}
		else {
			var ext = base.substring(base.length - 3, base.length);
			base = base.substr(0, base.length - 8);
		}
		
		if(index == 0){
			$("div#photo img").attr({src: base + suffix + "." + ext});		
			$("div#some-text div.top").html($(this).find("p").html());
			$("div#scrollable-photogallery a").removeClass("current")
			$(this).addClass("current");
			$("#edit").attr({href:"/portadmin/gc_good_edit.aspx?GoodID=" + $(this).children("div").text()})
		}
		
		$(this).click(function(){
			$("div#scrollable-photogallery a").removeClass("current")
			$(this).addClass("current");
			
			$("div#photo img").attr({src: base + suffix + "." + ext});			
			$("div#some-text div.top").html($(this).children("div.good-long-info").html());
			$("#edit").attr({href:"/portadmin/gc_good_edit.aspx?GoodID=" + $(this).children("div.good-id").text()})
			return false;
		});
	});
	
	s = $("div#scrollable-photogallery a:first").children("div.good-id").text();
	$("#edit").attr({href:"/portadmin/gc_good_edit.aspx?GoodID=" + s});


	$("div#news-gallery br").remove();	
	$("div#news-gallery img").wrap("<a href='#'></a>");
	$("div#news-gallery a").each(function(index, dom){
		
		var base = $(this).find("img").attr("src");
		var ext = base.substring(base.length - 3, base.length);
		base = base.substr(0, base.length - 8);

		if(index == 0){
			$("div#news-gallery a").removeClass("current")
			$(this).addClass("current");
			$("div#photo img").attr({src: base + suffix + "." + ext })
		}
		

		
		$(this).click(function(){			
			$("div#news-gallery a").removeClass("current")
			$(this).addClass("current");
			$("div#photo img").attr({src: base + suffix + "." + ext })
			
			return false;
		})
	});
	
	
}


function DetectCurrentMenu(){
	
	$("ul#menu a").each(function(index, domEl){
		if (document.location.pathname.indexOf($(this).attr("href")) != -1) {
			$(this).parent().addClass("current");
		}
	});

	$("ul#menu a:last").parent().addClass("last")
	
	
	
}

