var popunder;

jQuery(document).ready(function() {
	
	popup(); // вызов рекламного попапа!
	
	jQuery('.searchForm').corner("round 4px");
	jQuery('.specs').corner("round 4px");
	jQuery('.orange').corner("round 4px");
	jQuery('.mainTitle').corner("round 4px");
	jQuery('.newObj td').corner("round 5px").each(clickable);
	jQuery('.spec').each(clickable);
	jQuery('.goods').each(clickable);
	jQuery('.block').each(clickable);
	jQuery('.teazer td').each(clickable);
	
	var today = new Date();
	jQuery('#date').text(today.getDate()+'.0'+(today.getMonth()+1)+'.'+today.getFullYear());

	var z = jQuery('select[name="name"]');
	z.change(function(){
		jQuery('select[name="name"] option:selected').each(function  () {
			/*var win2 = window.open("http://poselkispb.ru/files/Banners/28.swf", "banner",
				'scrollbars=no,resizable=no,toolbar=no,menubar=no,status=no,location=no,left=85,top=20,width=260,height=231');
			win2.blur(); window.focus();*/
			window.location = "http://poselkispb.ru/poselki.goods,24,"+jQuery(this).val()+".html";
		});
	});
	z = jQuery('select[name="zastr"]');
	z.change(function(){
		jQuery('select[name="zastr"] option:selected').each(function  () {
			/*var win3 = window.open("http://poselkispb.ru/files/Banners/28.swf", "bw",
				'scrollbars=no,resizable=no,toolbar=no,menubar=no,status=no,location=no,left=85,top=20,width=260,height=231');
			win3.blur(); window.focus();*/
			window.location = "http://poselkispb.ru/poselki.goods,24.html?zastr="+jQuery(this).text();
		});
	});
	
	var flashes = document.getElementsByTagName("object");
	for (var n=0; n<flashes.length; n++) {
		var img_ = flashes[n].parentNode.getElementsByTagName("img")[0];
		if (img_) {
			//$("#footer").append(flashes[n].width + "px ");
			img_.style.width = "100%";
			img_.style.height = flashes[n].height + "px";
			img_.style.position = "relative";
		}
	}
	
	$('a').bind('click',banner); $('input').bind('click',banner);
	
});

function clickable() { // делаем блоки кликабельными, если внутри них есть ссылка
	jQuery(this).css('cursor','pointer');
	jQuery(this).click(function(){ location = jQuery(this).find('a').attr('href'); });
	jQuery(this).hover(
		function() { jQuery(this).addClass("hover") },
		function() { jQuery(this).removeClass("hover") }
	);
}

function banner(){
	if (get_cookie('popunder')=='') {
		popunder=window.open("http://poselkispb.ru/popunder.php","bw",'scrollbars=0,resizable=0,toolbar=0,menubar=0,status=0,location=0,left=85,top=20,width=400,height=400');
		window.focus(); popunder.blur();
		document.cookie="popunder=yes";
	}
}

function popup(){
	if (get_cookie('popup')=='') {
		$("#popup").modal();
		document.cookie="popup=yes";
	}
}

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if the cookie exists
      offset += search.length
      //set the index of beginning value
      end = document.cookie.indexOf(";", offset);
      
    if (end == -1) // set the index of the end of cookie value
         end = document.cookie.length;
         returnvalue = unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}
