$(document).ready(function(){
	Gallery();
	LightBox();
	PlaceHolder("#spam .text input");
	Slogan()
})

function Slogan(){
	var s = $("#slogans").text();
	if ($.browser.msie == false){
		s = s.replace(/#/g, "");
	}
	if (s.indexOf("\n") == -1){
		s1 = s.split("#");
	} else {
		s = s.replace("#","");
		s1 = s.split("\n");
	}
	l = s1.length;
	a = (l - 1) * Math.random();
	b = Math.round(a);
	$("#slogan").text(s1[b]);
}

function Gallery(){
	var obj = $("#photos-inner");
	var next = $("#slide-forward");
	var back = $("#slide-back");
	var containerWidth = $("#photos").width();
	var speed = 500;
	var step = 100; //на сколько пикселов двигаем
	var mainImg = $("#main-photo");
	var mainImgLink = $("#main-photo-link");

	var x = 0;
	obj.find("img").each(function(){
		x = x + $(this).width();
		/*$(this).click(function(){
			$(this).siblings().removeClass("active");
			$(this).addClass("active");
			mainImg.attr({src:$(this).attr("src").replace("_sml.","_mid.")});
			mainImgLink.attr({href: $(this).next().text()})
		});*/
	});


	if (x == 0) {
		x = 90 * obj.find("img").length
	}

	obj.width(x + 30)


	next.click(function(){
		if (obj.css("left").replace("px","") > (containerWidth - x) && $("#photos-inner:animated").length == 0){
			obj.animate({left: "-=" + step + "px"}, speed);
		}

		return false;
	})

	back.click(function(){
		if (obj.css("left").replace("px","") < 0 && $("#photos-inner:animated").length == 0){
			obj.animate({left: "+=" + step + "px"}, speed);
		}
		return false;
	})


/*		$("#photos-inner a").lightbox();
			$.Lightbox.construct({
				"speed" : 700,
				"show_linkback" : false,
				"keys" : {
					close : "q",
					prev : "z",
					next : "x"
				},
				"opacity" : 0.7,
				"rel" : "lightbox-1",
				text : {
					image : "Картинка",
					of : "из",
					close : "Закрыть",
					closeInfo : "Клик вне картинки завершит просмотр.",
					help : {
						close : "Закрыть",
						interact: ""
					},
					about : {
						text : "Можно вставить какую-нибудь ссылку",
						title : "И снабдить ее комментарием...",
						link : "http://www.linkexchanger.su/2008/65.html"
					}
				},
				files: {
					images: {
						prev:		'/img/prev.gif',
						next:		'/img/next.gif',
						blank:		'/img/blank.gif',
						loading:	'/img/loading.gif'
					}
				}
			});*/

}

function PlaceHolder(selector){
	$(selector).each(function(){
		var defaultText = $(this).val();
		$(this).focus(function(){
			if ($(this).val() == defaultText ){
				$(this).val("");
			}
		});
		 $(this).blur(function(){
			if ($(this).val() == ""){
				$(this).val(defaultText);
			}
		});
	})
}

function LightBox(){
	if ($("#photos2d").length > 0){
		$("#photos2d a").lightbox();
			$.Lightbox.construct({
				"speed" : 700,
				"show_linkback" : false,
				"keys" : {
					close : "q",
					prev : "z",
					next : "x"
				},
				"opacity" : 0.7,
				"rel" : "lightbox-1",
				text : {
					image : "Картинка",
					of : "из",
					close : "Закрыть",
					closeInfo : "Клик вне картинки завершит просмотр.",
					help : {
						close : "Закрыть",
						interact: ""
					},
					about : {
						text : "Можно вставить какую-нибудь ссылку",
						title : "И снабдить ее комментарием...",
						link : "http://www.linkexchanger.su/2008/65.html"
					}
				},
				files: {
					images: {
						prev:		'/img/prev.gif',
						next:		'/img/next.gif',
						blank:		'/img/blank.gif',
						loading:	'/img/loading.gif'
					}
				}
			});
	}
}