$(document).ready(function() {

function Size1000() {
$('#carrier').css('width','1000px').css('background-position','0 0');
$('#header').css('margin-left','25px').css('margin-right','10px');
$('#menugor').css('margin-left','25px');
$('#mainmenu').css('margin-left','25px');
$('#content').css('margin-left','0px');
$('ul#topnav > li > a').css('width','88px');
$('#mainmenu ul.ulcenter').css('margin-left','18px');
$('#tabs').css('margin-left','15px');
$('.ui-tabs').css('width','310px');
$('.ui-tabs .ui-tabs-nav li a').css('width','97px');
$('#left').css('width','697px');
$('#left .nc_list').css('padding-left','15px').css('padding-right','15px');
$('#order').css('padding-left','15px').css('padding-right','15px');
$('#sitemap').css('padding-left','15px').css('padding-right','15px');    
$('#footer').css('padding-left','16px').css('padding-right','16px');
$('#container').css('width','582px');
// portfolio
$("#container").clickCarousel({margin:8, shiftOnly: true});	
}

function Size1250() {
$('#carrier').css('width','1250px').css('background-position','-1000px 0');
$('#header').css('margin-left','50px').css('margin-right','35px');
$('#menugor').css('margin-left','50px');
$('#mainmenu').css('margin-left','50px');
$('#content').css('margin-left','25px');
$('ul#topnav > li > a').css('width','113px');
$('#mainmenu ul.ulcenter').css('margin-left','30px');
$('#tabs').css('margin-left','28px');
$('.ui-tabs').css('width','484px');
$('.ui-tabs .ui-tabs-nav li a').css('width','155px');
$('#left').css('width','897px');
$('#left .nc_list').css('padding-left','40px').css('padding-right','40px');
$('#order').css('padding-left','40px').css('padding-right','40px');
$('#sitemap').css('padding-left','40px').css('padding-right','40px');     
$('#footer').css('padding-left','41px').css('padding-right','41px');
$('#container').css('width','800px');
// portfolio
$("#container").clickCarousel({margin:25, shiftOnly: true});	
}


$('ul#topnav > li > a').each(function() {
	var textA = $(this).height();
	$(this).css({'padding-top':'15px','height':'24px'});
	if (textA > 18) $(this).css({'padding-top':'5px','height':'34px'});
});
$('ul#topnav > li > a[href*=silkscreen] ').css({'padding-top':'15px','height':'24px'});
$('ul#topnav > li > a[href*=company] ').css({'padding-top':'15px','height':'24px'});
$('ul#topnav > li > a[href*=price] ').css({'padding-top':'15px','height':'24px'});
$('ul#topnav > li > a[href*=on-line-order] ').css({'padding-top':'15px','height':'24px'});
$('ul#topnav > li > a[href*=contacts] ').css({'padding-top':'15px','height':'24px'});


$(window).resize(function() {
    if (1250<$(window).width()) Size1250()
    else Size1000();
});

function st() {if (1250<$(window).width()) {Size1250();}  else {Size1000();}}
$(function() {st();});

$('#order div.nc_item_front_addd').click(function (){
$('#order div.prev').show();
$('#order div.prev + div.nc_item_front').addClass('prev');
});
$('#order div.nc_item_back_addd').click(function (){
$('#order div.prevb').show();
$('#order div.prevb + div.nc_item_back').addClass('prevb');
});

$('.nc_item_clear').click(function (){
$(this).addClass('cl');
$('.cl + br + :file').attr('value','');
$(this).removeClass('cl');
});

$('#menugor a,#tabs a, ul.sidenav  a,#sidenavdop a').each(function() {
	var textAA = $(this).text();
	$(this).attr('title',textAA)
});

$("ul#topnav li:first").addClass('lifirst');
$("ul#topnav li:last").addClass('lilast');

// Tabs
var rand = Math.round(Math.random()*2);

$('#tabs').tabs({ selected: rand });

//Добавляем сполер
$('.spoiler').toggle(
	function(){
		$(this).children('.spoiler-body').fadeIn(2000);
		$(this).addClass('minus');
	}, 
	function(){
		$(this).children('.spoiler-body').fadeOut(2000);
		$(this).removeClass('minus');
	});

//On Hover Over Выпадающее меню
function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}
var config = {
	sensitivity: 2,
	interval: 100,
	over: megaHoverOver,
	timeout: 500,
	out: megaHoverOut
};
$("ul#topnav li .sub").css({'opacity':'0'});
$("ul#topnav li").hoverIntent(config);

});
