var iDOMLoaded = false;

jQuery(document).ready(function() {
    iDOMLoaded = true;

    // Clients on index page
    if ($(".clients")[0]) {
        $(".clients a img").each(
			function() {
			    var cln = $(this).clone().insertBefore($(this));
			    cln.attr("src", $(this).attr("srcbig"));
			    cln.attr("className", "cln");
			    cln.css({
			        'position': 'absolute',
			        'visibility': 'hidden'
			    });
			}
		);
        $(".clients a").hover(
	    	function() {
	    	    var orig = $(this).children("img:not(.cln)");
	    	    var cln = $(this).children("img.cln");
	    	    cln.stop();

	    	    cln.css("width", "200px");
	    	    cln.css("height", "56px");
	    	    cln.css("marginTop", "7px");
	    	    cln.css("visibility", "visible");
	    	    orig.css("visibility", "hidden");
	    	    cln.animate({ width: "250px", height: "70px", marginLeft: "-20px", marginTop: "0px" }, 150);
	    	},
	    	function() {
	    	    var cln = $(this).children("img.cln");
	    	    cln.stop();

	    	    cln.animate({ width: "200px", height: "56px", marginLeft: "0", marginTop: "7px" }, 150,
	    				function() {
	    				    var orig = $(this).siblings("img");
	    				    orig.css("visibility", "visible");
	    				    $(this).css("visibility", "hidden");
	    				}
	    		);
	    	}
	    );
    }


    // Works on index page
    if ($("#prev_work a")[0]) {
        $('#fisheye').Fisheye(
			{
			    maxWidth: 20,
			    items: 'a',
			    itemsText: 'span',
			    container: '#small_works_list',
			    scrollContainer: '#prev_work',
			    scrollOverHeight: 60,
			    scrollOverTop: 10,
			    scrollOverWidth: 350,
			    itemWidth: 43,
			    proximity: 90,
			    speed: 10,
			    halign: 'left'
			}
		);

    } /**/


    // Right menu on regular pages
    if ($(".main_menu")[0]) {
        $(".main_menu li:not(.select) ul").hide();

        // By Over
        $(".main_menu a").attr("id", function(arr) { return "li-a-id" + arr; });
        $(".main_menu")[0].bProcDo = false;
        $(".main_menu")[0].bOutProcDo = false;

        // By Click
        $(".main_menu li a").click(function() {
            if (this.parentNode.parentNode.className == "main_menu") {
                
                if ($(this).siblings()[0] != undefined && $(this).siblings()[0].tagName == "UL")
                    document.location.href = $(this).attr("href");
                    //setTimeout('document.location.href = \'' + $(this).attr("href") + '\'', 5);
                else
                    document.location.href = $(this).attr("href");
                
                //$(".main_menu li:not(.select) ul:visible").slideUp("slow");
                //$(this).next().slideDown("slow");
                
                return false;
            }
        });
    }

    // Theme select
    if ($(".theme_select")[0]) {
        $(".theme_select").click(
   			function() {
   			    if ($(".theme_select #ts_popup").queue().length == 0)
   			        $(".theme_select #ts_popup").slideToggle("fast");
   			}
		);
        if (document.all) {
            $(".theme_select").blur(
	   			function() {
	   			    setTimeout(function() { $(".theme_select #ts_popup").slideUp("fast"); }, 50);
	   			}
			);
        } else {
            $("body").click(
	   			function() {
	   			    if ($(".theme_select #ts_popup").queue("fx").length == 0) {
	   			        $(".theme_select #ts_popup").slideUp("fast");
	   			    }
	   			}
			); /**/
        }
    }

    // Tabs on portfolio
    if ($(".content ul.portfolio_view")[0]) {
        $(".content ul.portfolio_view").tabs({ fx: { opacity: 'toggle' }, selected: 0 });
    }
    if ($(".list_project")[0]) {
        $(".list_project li:not(.select) ul").hide();
        $(".list_project > li > a").click(
            function() {
                $(".list_project > li.select ul").slideUp("slow");
                $(".list_project > li.select").attr("className", "");
                if (this.parentNode.className == "select") this.parentNode.className = "";
                else this.parentNode.className = "select";
                $(this).siblings("ul").slideDown("slow");
                return false;
            }
        );
    }
});


function doSlide(id) {
	$(".main_menu")[0].bProcDo = true;
	$(".main_menu li ul:visible").slideUp("slow", function(){if($(this).queue().length == 0) $(".main_menu")[0].bProcDo = false;});
	$(id).next().slideDown("slow", function(){if($(this).queue().length == 0) $(".main_menu")[0].bProcDo = false;});
}

function checkTagName(obj, tag) {
	res = false;
	if(obj) {
		if(obj.tagName) {
			if(obj.tagName.toLowerCase() == tag.toLowerCase()) {
				res = true;
			}
		}
	}
	return res;
}

function changeTheme(url) {
	window.location = url;
	return false;
}
