var jQueryLoaderOptions = null;;
(function ($) {
    $.loader = function (option) {
        switch (option) {
        case 'close':
            if (jQueryLoaderOptions) {
                if ($("#" + jQueryLoaderOptions.id)) {
                    $("#" + jQueryLoaderOptions.id + ", #" + jQueryLoaderOptions.background.id).remove();
                }
            }
            return;
            break;
        case 'setContent':
            if (jQueryLoaderOptions) {
                if ($("#" + jQueryLoaderOptions.id)) {
                    if ($.loader.arguments.length == 2) {
                        $("#" + jQueryLoaderOptions.id).html($.loader.arguments[1]);
                    } else {
                        if (console) {
                            console.error("setContent method must have 2 arguments $.loader('setContent', 'new content');")
                        } else {
                            alert("setContent method must have 2 arguments $.loader('setContent', 'new content');");
                        }
                    }
                }
            }
            return;
            break;
        default:
            var options = $.extend({
                content: "<div>Loading ...</div>",
                className: 'loader',
                id: 'jquery-loader',
                height: 60,
                width: 200,
                zIndex: 30000,
                background: {
                    opacity: 0.4,
                    id: 'jquery-loader-background'
                }
            }, option);
        }
        jQueryLoaderOptions = options;
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
        var bgDiv = $('<div id="' + options.background.id + '"/>');
        bgDiv.css({
            zIndex: options.zIndex,
            position: 'fixed',
            top: '0px',
            left: '0px',
            width: maskWidth,
            height: maskHeight,
            opacity: options.background.opacity
        });

        bgDiv.appendTo("body");
        if (jQuery.bgiframe) {
            bgDiv.bgiframe();
        }
        var div = $('<div id="' + options.id + '" class="' + options.className + '"></div>');
        div.css({
            zIndex: options.zIndex + 1,
            width: options.width,
            height: options.height
        });
        div.appendTo('body');
        div.center();
        $(options.content).appendTo(div);
    };
    $.fn.center = function () {
        this.css("position", "fixed");
        this.css("top", ($(window).height() - this.outerHeight()) / 2 + $(window).scrollTop() + "px");
        this.css("left", ($(window).width() - this.outerWidth()) / 2 + $(window).scrollLeft() + "px");
        return this;
    }
})(jQuery);

(function ($) {
    $.fn.extend({
        animateToClass: function (to, duration, easing, callback) {
            if (!to) {
                return this;
            }

            styles = selectStyle(to);

            if (!styles) return this;

            return this.animate(styles, duration, easing, callback);
        }
    });

    function selectStyle(sel) {
        if (sel.substr(0, 1) != ".") {
            sel = "." + sel;
        }

        $(document.styleSheets).each(function (i, v) {
            if (attrClassTest = selectAttr(sel, v)) {
                attrClass = attrClassTest;
            }
        });

        if (!attrClass) {
            attrClass = Array();
        }

        objStyle = {}

        if (attrClass == "") {
            return false;
        }

        if (attrClass.match(";")) {
            attrClass = attrClass.split(";");
        } else {
            attrClass = [attrClass];
        }

        $(attrClass).each(function (i, v) {
            if (v != "") {
                v = v.split(":");
                v[0] = toCamelCase(v[0]);

                objStyle[v[0]] = $.trim(v[1]);
            }
        });
        return objStyle;
    }

    function selectAttr(sel, v) {
        attrClass = false;

        if ($.browser.msie) {
            if (v.rules.length > 0) {
                $(v.rules).each(function (i2, v2) {
                    if (sel == v2.selectorText) {
                        attrClass = v2.style.cssText;
                    }
                });
            } else if (v.imports.length > 0) {
                $(v.imports).each(function (i2, v2) {

                    if (sel == v2.selectorText) {
                        attrClass = v2.style.cssText;
                    } else if (v2 == "[object]" || v2 == "[Object CSSStyleSheet]" || v2 == "[object CSSImportRule]") {
                        return selectAttr(sel, v2);
                    }
                });
            }
        } else {
            $(v.cssRules).each(function (i2, v2) {
                if (sel == v2.selectorText) {
                    attrClass = v2.style.cssText;
                } else if (v2 == "[object CSSImportRule]") {
                    return selectAttr(sel, v2.styleSheet);
                }
            });
        }

        return attrClass;
    }

    function toCamelCase(str) {
        str = $.trim(str);
        str = str.replace(/-/g, " ");
        str = str.toLowerCase();

        strArr = str.split(" ");

        var nStr = "";
        $(strArr).each(function (i, v) {
            if (i == 0) {
                nStr += v;
            } else {
/*
				v = v.split("");
				v[0] = v[0].toUpperCase();
				nStr += v.join();
				*/

                //There was a bug in older version, this correction was sugested by Simon Shepard.
                nStr += v.substr(0, 1).toUpperCase();
                nStr += v.substr(1, v.length);
            }
        });

        return nStr;
    }
})(jQuery);
jQuery(function ($) {
    /**
     * Demo binding and preparation, no need to read this part
     */
    //borrowed from jQuery easing plugin
    //http://gsgd.co.uk/sandbox/jquery.easing.php
    $.easing.elasout = function (x, t, b, c, d) {
        var s = 1.70158;
        var p = 0;
        var a = c;
        if (t == 0) return b;
        if ((t /= d) == 1) return b + c;
        if (!p) p = d * .3;
        if (a < Math.abs(c)) {
            a = c;
            var s = p / 4;
        } else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
    };
    // back links
    $('a.back').click(function () {
        $(this).parents('div.pane').scrollTo(0, 800, {
            queue: true
        });
        $(this).parents('div.section').find('span.message').text(this.title);
        return false;
    });
    //just for the example, to stop the click on the links.
    $('ul.links').click(function (e) {
        e.preventDefault();
        var link = e.target;
        link.blur();
        if (link.title) $(this).parent().find('span.message').text(link.title);
    });

    // This one is important, many browsers don't reset scroll on refreshes
    // Reset all scrollable panes to (0,0)
    $('div.pane').scrollTo(0);
    // Reset the screen to (0,0)
    $.scrollTo(0);
clicks=0;
    // TOC, shows how to scroll the whole window
    $('.menuholder a[href!="portfolio/"]').click(function () { //$.scrollTo works EXACTLY the same way, but scrolls the whole screen
        thiselement = this;
        elem = $(thiselement).parent().parent().parent();
        parent2 = $(thiselement).parent().parent();
        $(parent2).fadeTo("fast", 0.5);
        $(".menu-active", elem).fadeTo("fast", 0.5);
        $.scrollTo(this.hash, 1200, {

            onAfter: function () {
                elem = $(thiselement).parent().parent().parent();
                parent2 = $(thiselement).parent().parent();
                $(".active", elem).remove();
                $(".menu-active", elem).removeClass("menu-active").addClass("menu-inactive").fadeTo("fast", 1);
                $(parent2).removeClass("menu-inactive").addClass("menu-active").fadeTo("fast", 1);
                $(parent2).append('<div class="active"></div>');
                $(".menu-inactive").fadeTo("fast", 1);
				 if (clicks==0){$foooclick();}
				 clicks=clicks+1;
            }
        });
        window.location.hash = this.hash;
        return false;
    });


});
$.fn.loadWithoutCache = function (){
 var elem = $(this);
 var func = arguments[1];
 $.ajax({
     url: arguments[0],
     cache: false,
     dataType: "html",
     success: function(data, textStatus, XMLHttpRequest) {
   elem.html(data);
   if(func != undefined){
    func(data, textStatus, XMLHttpRequest);
   }
     }
 });
 return elem;
}

$(document).ready(function () {
	$(".menuholder a").each(function(){$(this).attr("href",$(this).attr("src"))});
    $.loader({
        className: "blue-with-image-2",
        content: ''
    });
naem=0;
    $('#content div').each(function () {
        $(this).load($(this).attr("src"), function () {
             $(".readmore").fancybox({'type':'iframe','width': 990,'height':"80%",'autoScale'	: false, 'autoDimensions' :false});

             $(".boxed").fancybox({'type':'iframe','width': 990,'height':"80%",'autoScale'	: false, 'autoDimensions' :false});
             $(".map-images a").fancybox({
               'width'  : 990
            });
             $(".map-images21 a").fancybox({
               'width'  : 990
            });
			 $(".boxedi").fancybox({
               'width'	: 990
            });
		naem=naem+1;
		if (naem==6){
		loadall();
		
		}
        });

    });


});

$.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
});

function loadall() {
    $.scrollTo(0);
first=1; 
 $("#content div.startuphide").each(function () {
      if (first==1){ 
	   $(this).before("<div id=" + $(this).attr("name") + " class='invisible-ankor' ></div><div id=" + $(this).attr("name") + " class='invisible-ankor2'></div>");}else
	   {$(this).before("<div id=" + $(this).attr("name") + " class='invisible-ankor'></div><div id=" + $(this).attr("name") + " class='invisible-ankor2'></div>");}
first=2;
	   });
    $('.invisible-ankor').waypoint({
        offset: 40 // 100px from the top
    });
    $('.invisible-ankor2').waypoint({
        offset: 0 // 100px from the top
    });
    $('#studio').waypoint({
        offset:  0// 100px from the top
    });
    $('#contact').waypoint({
        offset: 200 // 100px from the top
    });
    $('body').delegate('.invisible-ankor', 'waypoint.reached', function (event, direction) {
        var $active = $(this);
        $(".active").remove();
        $(".menu-active").removeClass("menu-active").addClass("menu-inactive").fadeTo("fast", 1);
        $activeid = $('a[href=#' + $active.attr('id') + ']');
        parent2 = $activeid.parent().parent();
        $(parent2).removeClass("menu-inactive").addClass("menu-active").fadeTo("fast", 1);
        $(parent2).append('<div class="active"></div>');

    }); 

    $('body').delegate('.invisible-ankor2', 'waypoint.reached', function (event, direction) {
        var $active = $(this);
        $(".active").remove();
        $(".menu-active").removeClass("menu-active").addClass("menu-inactive").fadeTo("fast", 1);
        $activeid = $('a[href=#' + $active.attr('id') + ']');
        parent2 = $activeid.parent().parent();
        $(parent2).removeClass("menu-inactive").addClass("menu-active").fadeTo("fast", 1);
        $(parent2).append('<div class="active"></div>');

    });

    $('body').delegate('#studio', 'waypoint.reached', function (event, direction) {
        var $active = $(this);
        $(".active").remove();
        $(".menu-active").removeClass("menu-active").addClass("menu-inactive").fadeTo("fast", 1);
        $activeid = $('a[href=#' + $active.attr('id') + ']');
        parent2 = $activeid.parent().parent();
        $(parent2).removeClass("menu-inactive").addClass("menu-active").fadeTo("fast", 1);
        $(parent2).append('<div class="active"></div>');

    });
    $('body').delegate('#contact', 'waypoint.reached', function (event, direction) {
       
        var $active = $(this);
        $(".active").remove();
        $(".menu-active").removeClass("menu-active").addClass("menu-inactive").fadeTo("fast", 1);
        $activeid = $('a[href=#' + $active.attr('id') + ']');
        parent2 = $activeid.parent().parent();
        $(parent2).removeClass("menu-inactive").addClass("menu-active").fadeTo("fast", 1);
        $(parent2).append('<div class="active"></div>');

    });


    $(window).scroll(function () {

        if ($(window).scrollTop() > $(".sysiont1").offset().top) {

            $(".sysfixed1").css("position", "fixed");
            $(".sysfixed1").css("top", "160px");
            $(".sysfixed1").css({
                "left": "50%",
                "margin-left": "-465px"
            });
        }
        if (($(window).scrollTop() <= $(".sysiont1").offset().top) || (($(window).scrollTop() >= $(".sysiont1").offset().top + 400))) {

            $(".sysfixed1").css("position", "absolute");
            $(".sysfixed1").css("top", '');
            $(".sysfixed1").css({
                "left": "",
                "margin-left": "",
                "margin-top": "25px"
            });
        }
    });

        $(window).scroll(function () {

        if ($(window).scrollTop() > $(".sysiont2").offset().top) {

            $(".sysfixed2").css("position", "fixed");
            $(".sysfixed2").css("top", "160px");
            $(".sysfixed2").css({
                "left": "50%",
                "margin-left": "-465px"
            });
        }
        if (($(window).scrollTop() <= $(".sysiont2").offset().top) || (($(window).scrollTop() >= $(".sysiont2").offset().top + 250))) {

            $(".sysfixed2").css("position", "absolute");
            $(".sysfixed2").css("top", '');
            $(".sysfixed2").css({
                "left": "",
                "margin-left": "",
                "margin-top": "25px"
            });
        }
    });

    activeid = 'm1';

    $(".map-elem").hover(function () {
        idname = $(this).attr("id");
        $(this).addClass(idname + '-hover');
    }, function () {

        idname = $(this).attr("id");
        if (idname != activeid) {
            $(this).removeClass(idname + '-hover');
        }
    });


    $(".m-link li a").click(function () {
        $('#' + activeid).removeClass(activeid + '-hover');
        idname = $(this).attr("href");
        $('#' + idname).addClass(idname + '-hover');
        $('#' + activeid + '-link').attr('style', "color:#2D79A0;font-weight: normal;").parent().css({
            "background-color": ""
        });


        $('#' + activeid + '-text').toggle();
        $(this).attr('style', "color:#5b6776;font-weight: bold;");
        $(this).parent().css({
            "background-color": "#F7F9F9"
        });
        activeid = idname;
        $('#' + activeid + '-text').fadeIn();
        return false;
    });
    $(".m-link li a#" + activeid + '-link').click();
    $(".map-elem").click(function () {
        idname = $(this).attr("id");
        $(".m-link li a#" + idname + '-link').click();
    });

    activr = "id72157626416017445";
    activr1 = "id72157627019052010";

	$(".img-pack a").attr("href","document.php?from=gallery_1&id="+activr);
    $(".img-loadhere").load("document.php?from=gallery_2&id="+activr);
    $(".img-loadhere2").load("document.php?from=gallery_2&id="+activr1);

    $('a#id72157626416017445').attr('style', "color:#5b6776;font-weight: bold;");
    $('a#id72157626416017445').css({
        "background-color": "#F7F9F9"
    });

    $('a#'+activr1).attr('style', "color:#5b6776;font-weight: bold;");
    $('a#'+activr1).css({
        "background-color": "#F7F9F9"
    });


    $(window).scroll(function () {

        if ($(window).scrollTop() > $(".sysiont").offset().top) {

            $(".sysfixed").css("position", "fixed");
            $(".sysfixed").css("top", "160px");
            $(".sysfixed").css({
                "left": "50%",
                "margin-left": "-465px"
            });
        }
        if (($(window).scrollTop() <= $(".sysiont").offset().top) || (($(window).scrollTop() >= $(".sysiont").offset().top + 500))) {

            $(".sysfixed").css("position", "absolute");
            $(".sysfixed").css("top", '');
            $(".sysfixed").css({
                "left": "",
                "margin-left": "",
                "margin-top": "25px"
            });
        }
    });

    $(".main_news2 #" + activr).css({
        "display": "block"
    });
    $(".main_news21 #" + activr1).css({
        "display": "block"
    });

    $(".m-link2 a").click(function () {

        $('a[id="' + activr + '"][class!="s"]').attr('style', "color:#2D79A0;font-weight: normal;").parent().css({
            "background-color": ""
        });

        $(".map-images#" + activr).addClass('fade').animate({
            "right": "-450px",
            "opacity": "0"
        }, "fast", function () {
            $(".map-images").removeClass('fade').removeAttr("style").css({
                "display": "none"
            });
            $(".map-images#" + activr).css({
                "left": "-450px",
                "opacity": "0",
                "display": "block"
            });
            $(".map-images#" + activr).animate({
                "left": "0px",
                "opacity": "1"
            }, "fast", function () {
                $(".map-images#" + activr).removeAttr("style").css({
                    "display": "block"
                });

            });
        });

        activr = $(this).attr("id");
                $(".img-pack a").attr("href","document.php?from=gallery_1&id="+activr);

                    $(".img-loadhere").load("document.php?from=gallery_2&id="+activr);

                $(this).attr('style', "color:#5b6776;font-weight: bold;");
        $(this).parent().css({
            "background-color": "#F7F9F9"
        });
        return false;
    });


    $(".m-link21 a").click(function () {

        $('a#' + activr1 + '.s').attr('style', "color:#2D79A0;font-weight: normal;").parent().css({
            "background-color": ""
        });

        $(".map-images21#" + activr1).addClass('fade').animate({
            "right": "-450px",
            "opacity": "0"
        }, "fast", function () {
            $(".map-images21").removeClass('fade').removeAttr("style").css({
                "display": "none"
            });
            $(".map-images21#" + activr1).css({
                "left": "-450px",
                "opacity": "0",
                "display": "block"
            });
            $(".map-images21#" + activr1).animate({
                "left": "0px",
                "opacity": "1"
            }, "fast", function () {
                $(".map-images1#" + activr1).removeAttr("style").css({
                    "display": "block"
                });

            });
        });

        activr1 = $(this).attr("id");
              

                    $(".img-loadhere2").load("document.php?from=gallery_2&id="+activr1);

                $(this).attr('style', "color:#5b6776;font-weight: bold;");
        $(this).parent().css({
            "background-color": "#F7F9F9"
        });
        return false;
    });



	$(".inserthere").after('<iframe width="570" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.ru/maps?f=q&amp;source=s_q&amp;hl=ru&amp;geocode=&amp;q=%D0%B0%D0%BA%D0%B2%D0%B0%D1%84%D0%BE%D1%82%D0%BE%D1%81%D1%82%D1%83%D0%B4%D0%B8%D1%8F&amp;aq=&amp;sll=55.354135,40.297852&amp;sspn=42.638363,114.169922&amp;ie=UTF8&amp;hq=%D0%B0%D0%BA%D0%B2%D0%B0%D1%84%D0%BE%D1%82%D0%BE%D1%81%D1%82%D1%83%D0%B4%D0%B8%D1%8F&amp;hnear=&amp;cid=15167883315757227770&amp;ll=60.054131,30.340548&amp;spn=0.014996,0.036478&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe><br />');

	clickednum=0;
	oldclick=0;
	Cufon.replace('h1');
				function refresher(){
				$('.pagination a').unbind();
				$('.pagination a').click(function(){
				a=$(this);
				 oldclick=0+parseInt($(".sel-n").text())-1;
				 clickednum=0+parseInt(a.attr("href"));	 
				 father=a.parent().parent().parent();

				 $(".article-main:visible",father).fadeOut("fast",function(){	
				 $(".article-main[vid='"+(clickednum*6)+"']",father).fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+1)+"']",father).fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+2)+"']",father).fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+3)+"']",father).fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+4)+"']",father).fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+5)+"']",father).fadeIn("fast");
				 
				 });
				$(".sel-n").after("<a href="+(oldclick+0)+">"+(oldclick+1)+"</a>");
				$(".sel-n").remove();
				a.before("<span class='sel-n'>"+(clickednum+1)+"</span>");
				a.remove();
				refresher();
				return false;
				});
				}
	
		$( '.article-main',$('.blog-load-here').parent()).attr("style","display:none");
				 $(".article-main[vid='"+(clickednum*6)+"']").fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+1)+"']").fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+2)+"']").fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+3)+"']").fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+4)+"']").fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+5)+"']").fadeIn("fast");
refresher();
	$('.pagination a:first').click(); 
	$('.blog-cat-selector a').click(function(){
	$('.blog-load-here').load('blog-generator.php?cat='+$(this).attr("catid"),function(){
	Cufon.replace('h1');	clickednum=0;
	oldclick=0;             $(".readmore").unbind().fancybox({'type':'iframe','width': 990,'height':"80%",'autoScale'	: false, 'autoDimensions' :false});

			$( '.article-main',$('.blog-load-here').parent()).attr("style","display:none");
				 $(".article-main[vid='"+(clickednum*6)+"']").fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+1)+"']").fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+2)+"']").fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+3)+"']").fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+4)+"']").fadeIn("fast");
				 $(".article-main[vid='"+(clickednum*6+5)+"']").fadeIn("fast");
	refresher();
	});
	return false;
	});
    $('.startuphide').fadeIn('fast');
	    var destination = window.location.hash;
    if (destination == '') {
        $(".active").remove();
        $(".menu-active").removeClass("menu-active").addClass("menu-inactive").fadeTo("fast", 1);
        $activeid = $('a[href=#studio]');
        parent2 = $activeid.parent().parent();
        $(parent2).removeClass("menu-inactive").addClass("menu-active").fadeTo("fast", 1);
        $(parent2).append('<div class="active"></div>');
    } else {
        $('a[href="' + destination + '"]').click();
    }
    $.loader('close');

};
