jQuery (document).ready(function (){
	function setposition(){
		var object = jQuery ("#header");
		var header = object.offset();
		jQuery ("#logo").css({"top":"40px", "left":header.left-30 + "px"});
		jQuery ("#facebook").css({"top":"4px", "left":((object.width()+header.left)-131) + "px"});
	}
	
	function OverLayPosition (){
		jQuery ("#overlay").css ({"height":jQuery(window).height(),"width":jQuery(window).width()});
	}
	
	jQuery (window).resize (function (){
		setposition ();
		var winWidth = jQuery (window).width();
	})
	jQuery (document).pngFix();
	setposition ();
	OverLayPosition();
	jQuery.fn.centerScreen = function(loaded) {
		var obj = this;
		if(!loaded) {
			obj.css('top', $(window).height()/2-this.height()/2);
			obj.css('left', $(window).width()/2-this.width()/2);
			$(window).resize(function(){ obj.centerScreen(!loaded); });
		} else {
			obj.stop();
			obj.animate({ top: $(window).height()/2-this.height()/2, left: $(window).width()/2-this.width()/2}, 200, 'linear');
		}
    } 
	
	
	jQuery ("#photos a").click (function (){
		jQuery ("#modelbox img").attr ("src", jQuery(this).attr("href"));
		jQuery ("#facebook").fadeTo ("fast", 0.33);
		jQuery ("#modelbox").show().centerScreen();
		
		var scrollTop = jQuery(window).scrollTop();
		var scrollHeight = ($(window).height() - jQuery ("#modelbox").height());//506
		var remainHeight = (scrollHeight/2);
		jQuery ("#overlay").css ({'top': (scrollTop) + 'px', 'display':'block'}).fadeTo ("fast",0.90)
    	jQuery ("#modelbox").css ({'top': (scrollTop+remainHeight) + 'px'})
		return false;
	})


	jQuery ("#castU a").click (function (){
                var txtObj = "#" + jQuery(this).attr("href");
jQuery ("#modelbox #inlineText").html (jQuery (txtObj).html())
		jQuery ("#modelbox").show().centerScreen();
		var scrollTop = jQuery(window).scrollTop();
		var scrollHeight = ($(window).height() - jQuery ("#modelbox").height());//506
		var remainHeight = (scrollHeight/2);
		jQuery ("#overlay").css ({'top': (scrollTop) + 'px', 'display':'block'}).fadeTo ("fast",0.90)
                jQuery ("#modelbox").css ({'top': (scrollTop+remainHeight) + 'px'})
		return false;
	})


	
	jQuery (window).scroll(function (e) { 
		var scrollTop = jQuery(window).scrollTop();
		var scrollHeight = ($(window).height() - jQuery ("#modelbox").height());//506
		var remainHeight = (scrollHeight/2);
		jQuery ("#overlay").css ({'top': (scrollTop) + 'px'})
    	jQuery ("#modelbox").css ({'top': (scrollTop+remainHeight) + 'px'})
    });
	
	
	jQuery(".modelbox .close a, .modelbox2 .close2 a").hover(function () {
		jQuery(this).addClass("selected");
	},function () {
		jQuery(this).removeClass("selected");
	});
	
	jQuery(".modelbox .close a, .modelbox2 .close2 a").click (function (){jQuery ("#modelbox").hide (); jQuery ("#overlay").css ('display','none'); jQuery ("#modelbox img").attr ("src", "images/the-music/photo-no.jpg"); return false;})

	

})
