var modal;
function gup(name,href){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( href );
  if( results == null )
    return "";
  else
    return results[1];
}
jQuery(function ($) {
	modal = {
		html: null,
		message: null,
		init: function () {
			$(modal.html).modal({
				closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
				position: null,//["15%",],
				overlayId: 'modal-overlay',
				containerId: 'modal-container',
				onOpen: modal.open,
				onShow: modal.show,
				onClose: modal.close,
				appendTo: "body",
				focus: true,
				opacity: 40,
				overlayCss: {},
				containerCss: {},
				dataId: "modal-data",
				dataCss: {},
				minHeight: null,
				minWidth: null,
				maxHeight: null,
				maxWidth: null,
				autoResize: true,
				autoPosition: true,
				zIndex: 1E3,
				close: true,
				closeClass: "modal-close",
				escClose: false,
				overlayClose: true,
				persist: false,
				modal: true
			});
		},
		open: function (dialog) {
			dialog.overlay.fadeIn(200, function () {
				dialog.container.fadeIn(200, function () {
					dialog.data.fadeIn(200, function () {
						$(".sunder_page .content .icice .yazicik .bolum:last").css({"margin-right":"0","padding-right":"0","border":"none"});
						$(".sunder_post .content .icice .yazicik p:last").css({"margin":"0"});
						var hu = $(".sunder_page .content .icice .yazicik .bolum:first").height();
						$(".sunder_page .content .icice .yazicik .bolum.iki").css("height",hu);
                        if(ie==true){
                        	$(".lightbox,#header .orta .pano span,.sunder_page .content .icice .yazicik .iletisim input[type=text],.sunder_page .content .icice .yazicik .iletisim input[type=submit],.sunder_page .content .icice .yazicik .iletisim textarea,.sunder_post .soc2,.navigation a,.navigation span.current").each(function(){
                        		PIE.attach(this);
                        	});	                            
                        }
						$(".navigation a").each(function(){
							var href = $(this).attr("href");
							var cat = $(".other ul").attr("id");
							var page = gup("paged",href);
							$(this).attr("class","cat_"+page);
							$(this).attr("id","cat_"+cat);							
						});								
					});
				});
			});
		},
		show: function (dialog) {			
		},
		close: function (dialog) {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$.modal.close();
					});
				});
			});
		},
		error: function (xhr) {alert(xhr.statusText);},
		showError: function () {}
	};
	
	$('.modal').click(function (e) {
		e.preventDefault();
		modal.html = $($(this).attr('href')).html();
		modal.init();
		return false;

	});
});
