var Site = {

	initialize: function(){
	    
		hs.registerOverlay(
			{
				thumbnailId: null,
				overlayId: 'controlbar',
				position: 'top right',
				hideOnMouseOut: true
			}
		);
		
		hs.graphicsDir = 'images/highslide/graphics/';
		hs.outlineType = 'rounded-white';
		hs.align = 'center';
		hs.captionEval = 'this.thumb.title';
		
		this.preloadImages("images/bg_txts.gif","images/bg_menu_on.gif");
	    
	}, // initialize

	
	domReady: function() {
	
		this.activateMainLists();
		this.activateInputs();
		this.columnsHeight();
		this.activateTemplateInfo();
		this.activateImageTemplate();
		this.voivodshipsDisabler('countryId','voivodshipId');
		this.voivodshipsDisabler('countryIdIv','voivodshipIdIv');
		this.voivodshipsDisabler('countryIdMail','voivodshipIdMail');
		this.voivodshipsDisabler('select_country','select_state');
		this.activateInfoFrames();
	}, // domReady

	voivodshipsDisabler: function(countryBoxName, voivodshipBoxName) {
		var country = $('#'+countryBoxName);
		var voivodship = $('#'+voivodshipBoxName);
		var regon = $('#regon');
		
		if (country && voivodship) {
			country.change( function () { 
				if (country.val() != 21) {
					voivodship.attr("disabled","disabled");
					if ((countryBoxName == 'countryId' && !$('#countryIdIv').val()) || countryBoxName == 'countryIdIv') {
						regon.attr("disabled","disabled");
						$('#regon_required').css('display', 'none');
					}
				} else {
					voivodship.removeAttr("disabled");
					if ((countryBoxName == 'countryId' && !$('#countryIdIv').val()) || countryBoxName == 'countryIdIv') {
						regon.removeAttr("disabled","disabled");
						$('#regon_required').css('display', 'inline');
					}
				}
			}).change();
		}
	}, // voivodshipsDisabler
	
	preloadImages: function() {
		for(var i = 0; i<arguments.length; i++) {
			jQuery("<img>").attr("src", arguments[i]);
		}
	}, //preloadImages
    
	columnsHeight: function() {
		
		var left = $("div#white div.left").height();
		var right = $("div#white div.right").height();
		if(left > right) {
			$("#column_helper").css('height', left - right - 13 + 'px');	
		}
		
	}, //columnsHeight
	
	formLabelsHeight: function() {
	   
	}, //formLabelsHeight
	
	activateMainLists: function() {
	
		if($('#offers')) {
			$("#offers span.open_settings").unbind("click");
			$("#offers").sortable({
				placeholder: "ui-selected", 
				handle: ".move",
				revert: true,
				opacity: 0.7,
				zIndex: 1500,
				stop: function() { $.cookie('offers_boxes', $("#offers").sortable("serialize"), { expires: 365 }); }
			});
			
			$(".settings").hide();
			
			$("#offers span.open_settings").click(function() {
				$(this).parent().parent().next().slideToggle("normal");
				return false;
			});
		}

	}, //activateMainLists

	activateInputs: function() {

		$(":text").each(function(){ if(!this.value) this.value = this.title; });
		$(":text").focus(function(){ if(this.value == this.title) this.value = ''; });
		$(":text").blur(function(){ if(this.value == '') this.value = this.title; });

	}, //activateInputs
	
	showMail: function(user, domain, contry, attr) {
		var start = "<a href=\"mailto:" + user + "@" + domain + "." + contry + "\"" + attr + ">";
		var end = "</a>";
		document.write(start + user + "@" + domain + "." + contry + end);
		return false;
	}, // showMail
	
	activateTemplateInfo: function() {

	    if ($(".employer_template")) {
	        $("input[@name=offer_type]").click(function(){
	            if ($(this).val() == 2) {
	                $(".choose_template_box").hide();
                    $(".employer_template").show();
	            } else {
	                $(".choose_template_box").show();
	                $(".employer_template").hide();
	            }
	        });
	        if ($("input[@name=offer_type]:checked").val() == 2) {
                $(".choose_template_box").hide();
                $(".employer_template").show();
	        }
	    }

	}, //activateInputs
	
	activateImageTemplate: function() {

	    if ($(".employer_template")) {
	        $("input[@name=template]").click(function(){
	            if ($(this).val() == 'IMAGE') {
	                $("#image_upload").show();
	            } else {
	            	$("#image_upload").hide();
	            }
	        });
	        if ($("input[@name=template]:checked").val() == 'IMAGE') {
                $("#image_upload").show();
	        }
	    }

	}, //activateInputs
	
	activateInfoFrames: function() {

	    if ($(".info_frame_act_01")) {
	    	$(".info_frame_act_01").mouseover(function(){
	    		$("#info_frame_01").show();
	        });
	    	$(".info_frame_act_01").mouseout(function(){
	    		$("#info_frame_01").hide();
	        });
	    }

	} //activateInfoFrames
	
};


function print_r(theObj){
	if(theObj.constructor == Array || theObj.constructor == Object) {
		document.write("<ul>")
		for(var p in theObj){
		  if(theObj[p].constructor == Array||
			theObj[p].constructor == Object){
			document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
			document.write("<ul>")
			print_r(theObj[p]);
			document.write("</ul>")
		  } else {
			document.write("<li>["+p+"] => "+theObj[p]+"</li>");
		  }
		}
		document.write("</ul>")
	}
} // print_r

// wyswietla o
function open_window(url,title,x,y) {
	// window.open(url, title,'scrollbars, height='+y+',width='+x);
	// poprawiona wersja dla IE
	window.open(url, '_blank','scrollbars=yes, height='+y+',width='+x);
}

Site.initialize();
$().ready(function (){ Site.domReady(); });