jQuery(function() {
	$.fn.startCarousel = function() {
  		var bodywidth = $('.mycont').width(),
			itemwidth = $('.mycarousel li').outerWidth(true);
			$('.mycarousel li').css('clear','');
			count = bodywidth / itemwidth | 0;
			widots = bodywidth - count*itemwidth;
			ots = widots/(count-1) | 0;
			if (ots < 20) {
				count = count-1;
				widots = bodywidth - count*itemwidth;
				ots = widots/(count-1) | 0;
			}
			$('.mycarousel li').eq(count).css('margin-left','');
			$('.mycarousel li').css('margin-left',ots);
			$('.mycarousel li').eq(count).css('clear','left');
			$('.mycarousel li').eq(count).css('margin-left','0px');
			$('.mycarousel li:first').css('margin-left','0px');
			
			if (bodywidth < 1000) $('#quote').css('font-size','17px');
			if (bodywidth > 1000 && bodywidth < 1100) $('#quote').css('font-size','19px');
			if (bodywidth > 1100 && bodywidth < 1200) $('#quote').css('font-size','21px');
			if (bodywidth > 1300) $('#quote').css('font-size','24px');
  	};
	
	$(this).startCarousel();
	
	$(window).resize(function(){
		$(this).startCarousel();
	});
	
	$('.mycarousel').jcarousel({
		scroll:2
	});
});

jQuery(function() {
	$.fn.smartColumns = function () {
		var bodywidth = $("#por").width(),
		itemwidth = $('ul.column li').outerWidth(true);
		$('ul.column li').css('clear','');
		count = bodywidth / itemwidth | 0;
		widots = bodywidth - count*itemwidth;
		ots = widots/(count-1) | 0;
		if (ots < 14) {
			count = count-1;
			widots = bodywidth - count*itemwidth;
			ots = widots/(count-1) | 0;
		}
		for (i=1;i<6;i++) {
			$('ul.column li').eq(count*i).css('margin-left','');
		}
		$('ul.column li').css('margin-left',ots);
		for (i=1;i<6;i++) {
			$('ul.column li').eq(count*i).css('clear','left');
			$('ul.column li').eq(count*i).css('margin-left','0px');
		}
		$('ul.column li:first').css('margin-left','0px');
	}
	$(this).smartColumns();
	$(window).resize(function () {
		$(this).smartColumns();
	});
	$('ul.column').jcarousel({
		scroll:2
	});
});

jQuery(function() {
	$.fn.Category = function () {
		jQuery('.spoiler-head').click(function(){
			jQuery('.spoiler-body').toggleClass("folded").slideToggle(600);
			if (document.getElementById('per_line').innerHTML=='Показать категории') {
				document.getElementById('per_line').innerHTML = 'Скрыть категории';
			}
			else document.getElementById('per_line').innerHTML = 'Показать категории';
		})
	}
	$(this).Category();
})


function naveden(what) {
	what.style.backgroundColor = '#c0fbc8';
}
function nenaveden(what) {
	what.style.backgroundColor = '';
}

function linklist_add(what){
	var selectedopt=what.options[what.selectedIndex];
	window.location="portfolio.php?id=add&option="+selectedopt.value;
}


function mycarousel_itemLoadCallback(carousel, state) {
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }
    jQuery.get(
        'dynamic_ajax_php.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};
 function mycarousel_itemAddCallback(carousel, first, last, xml) {
    carousel.size(parseInt(jQuery('total', xml).text()));
    jQuery('article', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery('id',this).text(),jQuery('image',this).text(),jQuery('title',this).text()));
    });
};
function mycarousel_getItemHTML(id,url,title) {
    return '<a href="/articles/articles.php?id='+id+'"><img src="' + url + '" width="213" height="138" alt="'+title+'" title="'+title+'" /></a><div>'+title+'</div>';
};
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        itemLoadCallback: mycarousel_itemLoadCallback
    });
});

$(function() {
    $(".carusel_articles").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev"
    });
});

function select_input(value,text) {
	if (value.value == text) value.value = '';
}
function input(value,text) {
	if (value.value == '') {
		value.value = text;
	}
}

var reg = null;
function initXMLHTTPRequest() {
	var xRequest=null;
	if (window.XMLHttpRequest) xRequest = new XMLHttpRequest();
	else if (window.ActiveXObject) xRequest = new ActiveXObject("Microsoft.XMLHTTP");
	return xRequest;
}
function sendRequest(url,HttpMethod) {
	reg=initXMLHTTPRequest();
	if (reg) {
		reg.onreadystatechange=onReadyState;
		reg.open(HttpMethod,url,true);
		reg.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		reg.send(optionElement());
	}
}
function onReadyState() {
	var ready=reg.readyState;
	var data=null;
	if (ready==4) {
		data=reg.responseText;
		document.getElementById('submit').disabled = '';
		select1 = document.getElementById('category');
		select1.disabled = '';
		if (data == '') select1.disabled = 'disabled';
		else select1.innerHTML = data;
				
	}
}
function optionElement() {
	var select1 = document.getElementById('section');
	for (var i=0; i < select1.options.length; i++) {
		if (select1.options[i].selected) {
			break;
		}
	}
	return 'section_id='+select1.options[i].value;
}




function sendform(section) {
	if (section == 'site') {
		required = new Array("goal_site","structure_site","osob_fun_site","desig_site","lang_version","content_site","index_page","date_begin","example_nice_site","example_bad_site","fio","e_mail","telephone","city");
	}
	if (section == 'logo') {
		required = new Array("about_company","audit","word_object_logo","style_logo","color_logo","where_logo","content_logo","date_zapusk","example_nice_logo","example_bad_logo","fio","e_mail","telephone","city");
	}
	if (section == 'banner') {
		required = new Array("about_company","audit","emoch","style_banner","color_banner","size_banner","technologi","date_zapusk","example_nice_banner","example_bad_banner","content_banner","fio","e_mail","telephone","city");
	}
	var i, j, p, error, element;
	for(j=0; j<required.length; j++) {
		for (i=0; i<document.forms[0].length; i++) {
			element = document.forms[0].elements[i];
			if (element.name == 'fio' && element.value == 'Введите свое имя') element.value = '';
			if (element.name == 'e_mail' && element.value == 'Введите свой email') element.value = '';
			if (element.name == 'telephone' && element.value == 'Введите свой телефон') element.value = '';
			if (element.name == 'city' && document.forms[0].elements[i].value == 'Введите свой город') element.value = '';
			if (element.name == required[j] && element.value == "" ) {
				element.style.borderColor='red';
				element.focus();
				error = 1;
			}
			if (element.name == required[j] && element.value != "" ) element.style.borderColor='';
		}
	}
	if (error == 1) return false;
}

function sendFormContent(value) {
	if (value.value == '') {
		value.style.borderColor='red';
		value.focus();
	}
	if (value.value != '') value.style.borderColor='';
}
