function basename (path, suffix) {
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

jQuery(function(){
	
 

	var blocks = new Array('about','client','part','port','usl','cshow_work');
	var colors = new Array();
	colors['about']="#7de002";
	colors['client']="#fbd307";
	colors['part']="#15a7ff";
	colors['port']="#ff68e6";
	colors['usl']="#ff8b19";
	var blocks_coords = new Array();
	blocks_coords['client'] = {show:316,hide:299};
	blocks_coords['about'] = {show:30,hide:89};
	blocks_coords['part'] = {show:200,hide:184};
	blocks_coords['cshow_work'] = {show:500,hide:184};
	blocks_coords['tel'] = {show:484,hide:469};
	blocks_coords['addr'] = {show:547,hide:532};
	blocks_coords['usl'] = {show:30,hide:89};
	blocks_coords['site'] = {show:474,hide:459};
	blocks_coords['stili'] = {show:447,hide:432};
	blocks_coords['arts'] = {show:414,hide:399};
	blocks_coords['polygraphy'] = {show:429,hide:414};
	blocks_coords['cport'] = {show:29,hide:14};

	var shadows_coords = new Array();
	shadows_coords['client'] = {show:601,hide:614};
	shadows_coords['about'] = {show:601,hide:614};
	shadows_coords['part'] = {show:589,hide:604};
	shadows_coords['tel'] = {show:521,hide:536};
	shadows_coords['addr'] = {show:589,hide:604};
	shadows_coords['usl'] = {show:601,hide:614};
	shadows_coords['site'] = {show:599,hide:614};
	shadows_coords['stili'] = {show:575,hide:590};
	shadows_coords['arts'] = {show:542,hide:557};
	shadows_coords['polygraphy'] = {show:557,hide:572};
	shadows_coords['cport'] = {show:599,hide:614};
	
				
	function showPortLine(suffix){
		$(".pol_port"+suffix).fadeIn(500);
	}
	function hidePortLine(suffix){
		$(".pol_port"+suffix).fadeOut(500);
	}
	function showPort(){
		showPortLine("_main");
                showPortLine("_z");
		showPortLine("_f");
		showPortLine("_s");
		showAdv("site");
		showAdv("stili");
		showAdv("polygraphy");
                showAdv("arts");
	}
	function hidePort(){
		hideAdv("site");removePort("site");
                hideAdv("arts");removePort("arts");
		hideAdv("stili");removePort("stili");
		hideAdv("polygraphy");removePort("polygraphy");
		hidePortLine("_main");removePortLine("_main");
                hidePortLine("_z");removePortLine("_z");
		hidePortLine("_f");removePortLine("_f");
		hidePortLine("_s");removePortLine("_s");
	}
	
	function showAdv(name){
		$("."+name+"_block").animate({opacity:"show",top:blocks_coords[name].show+"px"},{queue:false,duration:500});
		$("."+name+"_shadow").animate({opacity:"show",top:shadows_coords[name].show+"px"},{queue:false,duration:500});
	}
	function hideAdv(name){
		$("."+name+"_block").animate({opacity:"hide",top:blocks_coords[name].hide+"px"},{queue:false,duration:500});
		$("."+name+"_shadow").animate({opacity:"hide",top:shadows_coords[name].hide+"px"},{queue:false,duration:500});
	}
	function showIt(name){
	                if(name.localeCompare("about")==0){var callsub = function(){$(".history").click();}}
                if(name.localeCompare("usl")==0){var callsub = function(){$(".stylelogo").click();}}
		if(name.localeCompare("port")==0){showPort();return;}
		if(name.localeCompare("cport")!=0){$(".pol_"+name).fadeIn(500);}
		$("."+name+"_block").animate({opacity:"show",top:blocks_coords[name].show+"px"},{queue:false,duration:500,complete:callsub});
		$("."+name+"_shadow").animate({opacity:"show",top:shadows_coords[name].show+"px"},{queue:false,duration:500});
	}
	function hideIt(name){
        $('.chooser').css('display','none');
		if(name.localeCompare("port")==0){hidePort();return;}
		$("."+name+"_block").animate({opacity:"hide",top:blocks_coords[name].hide+"px"},{queue:false,duration:500});
		$("."+name+"_shadow").animate({opacity:"hide",top:shadows_coords[name].hide+"px"},{queue:false,duration:500});
		$(".pol_"+name).fadeOut(500);
		$('.chooser_c').css('display','none');
		
	}
        function remove(name){
            $("."+name+"_block, .pol_"+name+", ."+name+"_shadow").remove();
        }
        function removePort(name){
            $("."+name+"_block, ."+name+"_shadow").remove();
        }
        function removePortLine(suffix){
            $(".pol_port"+suffix).remove();
        }
        function hideAll(){
            hideIt("client");remove("client");
            hideAdv("addr");remove("addr");
            hideAdv("tel");remove("tel");
            hideIt("cport");remove("cport");
            $(".sidebar_port_menu").hide();
            hideIt("usl");remove("usl");
            hideIt("port");remove("port");
            hideIt("part");remove("part");
            hideIt("about");remove("about");
			hideIt("about");remove("about");
			$(".cshow_work_block").remove();
        }


        $(".about").livequery('click',function(){
            $.ajax({
                url:'/page/about/format/html',
                dataType: 'html',
                beforeSend: function(xhr){
                            hideAll();
                        },
                error: function(xhr,msr){alert("Error :(");},
                success: function(data){
                            $(".wrapper").append(data);
                            $('.pol_about').hide(); $('.about_block').hide(); $('.about_shadow').hide();
                            showIt("about");
                        }
            });
            return false;
        });
		/* $(".galery_pic").livequery('click',function(){
            var el_id = $(this).attr('id');
			$.ajax({
                url:'/portfolio/work/',
				data:'format=html&pic_id='+el_id,
                dataType: 'html',
                beforeSend: function(xhr){
                            hideAll();
							hidePort();
							
							
                        },
                error: function(xhr,msr){alert(xhr.responseText);alert("Error :(");},
                success: function(data){
                            $(".wrapper").append(data);
                            $('.pol_about').hide(); $('.about_block').hide(); $('.about_shadow').hide();
                            showIt("about");
						}
            });
            return false;
        });
		
		
        function bindSubCh(name){
            $("."+name).livequery('click',function(){
            $.ajax({
                url:'/page/subsection/'+name+'/format/html',
                dataType: 'html',
                beforeSend: function(xhr){
                            $('.content_wrapper').empty();
                        },
                error: function(xhr,msr){alert("Error :(");},
                success: function(data){
                            $('.content_wrapper').html($(data).fadeIn(400));
                        }
            });
            return false;
        });
        }*/
        //bindSubCh("history");
        //bindSubCh("partner");
        //bindSubCh("stylelogo");
        //bindSubCh("seo");
        //bindSubCh("sites");
        //bindSubCh("poly");

        $(".usl").livequery('click',function(){
            $.ajax({
                url:'/page/usl/format/html',
                dataType: 'html',
                beforeSend: function(xhr){
                            hideAll();
                            hidePort();
                        },
                error: function(xhr,msr){alert("Error :(");},
                success: function(data){
                            $(".wrapper").append(data);
                            $('.pol_usl').hide(); $('.usl_block').hide(); $('.usl_shadow').hide();
                            showIt("usl");
                        }
            });
            return false;
        });
        $(".client").click(function(){
            $.ajax({
                url:'/page/client/format/html',
                dataType: 'html',
                beforeSend: function(xhr){
                            hideAll();
                            hidePort();
                        },
                error: function(xhr,msr){alert("Error :(");},
                success: function(data){
                            $(".wrapper").find(".a_loader").remove();
                            $(".wrapper").append(data);




                            $('.pol_client').hide(); $('.client_block').hide(); $('.client_shadow').hide();
                            showIt("client");
                        }
            });
            return false;
        });
        $(".part").click(function(){
            $.ajax({
                url:'/page/part/format/html',
                dataType: 'html',
                beforeSend: function(xhr){
                            hideAll();
                            hidePort();
                        },
                error: function(xhr,msr){alert("Error :(");},
                success: function(data){
                            $(".wrapper").append(data);
                            $('.pol_part').hide(); $('.part_block').hide(); $('.part_shadow').hide();
                            $('.tel_block').hide(); $('.tel_shadow').hide();
                            $('.addr_block').hide(); $('.addr_shadow').hide();
                            showIt("part");
                            showAdv("tel");
                            showAdv("addr");
                        }
            });
            return false;
        });
        $(".port").livequery('click',function(){
            $.ajax({
                url:'/portfolio/main/format/html',
                dataType: 'html',
                beforeSend: function(xhr){
                            hideAll();
                            hidePort();
                        },
                error: function(xhr,msr){alert("Error :(");},
                success: function(data){
                            $(".wrapper").prepend(data);
                            $('.pol_port_main').hide();
                            $('.pol_port_z').hide();
                            $('.pol_port_f').hide();
                            $('.pol_port_s').hide();
                            $('.site_block').hide(); $('.site_shadow').hide();
                            $('.stili_block').hide(); $('.stili_shadow').hide();
                            $('.polygraphy_block').hide(); $('.polygraphy_shadow').hide();
                            $('.arts_block').hide(); $('.arts_shadow').hide();
                            showIt("port");
                        }
            });
            return false;
        });
        function bindSubPort(name){
            $("."+name).livequery('click',function(){
                $.ajax({
                    url:'/portfolio/'+name+'/format/html',
                    dataType: 'html',
                    beforeSend: function(xhr){
                                hideAll();
                                hidePort();
                            },
                    error: function(xhr,msr){alert("Error :(");},
                    success: function(data){
                                
                                $(".wrapper").append(data);
                                $('.pol_port_main').hide();
                                $('.cport_block').hide(); $('.cport_shadow').hide();
                                showIt("cport");
                            }
                });
                return false;
            });
        }
        bindSubPort('site');
        bindSubPort('stili');
        bindSubPort('polygraphy');
        bindSubPort('arts');

        $(".close a, .close_forcli a").livequery('click',function(){
            hideAll();
			if($(this).parent().attr('id') == 'work')
			{
				 var name = $(this).parent().attr('rel');
				 $.ajax({
                    url:'/portfolio/'+name+'/format/html',
                    dataType: 'html',
                    beforeSend: function(xhr){
                                hideAll();
                                hidePort();
                            },
                    error: function(xhr,msr){alert("Error :(");},
                    success: function(data){
                                
                                $(".wrapper").append(data);
                                $('.pol_port_main').hide();
                                $('.cport_block').hide(); $('.cport_shadow').hide();
                                showIt("cport");
                            }
                });
            
			}
			return false;
        });

	function bindColor(target){
		$(".menu_"+target).hover(function(){
			$(".color_"+target).animate({width:"123px"},{duration:150,easing:'easeOutQuint'});
			$(this).find('a').css("color","#333");
		},function(){
			$(".color_"+target).stop().animate({width:"0px"},{duration:700,easing:'easeOutQuint'});
			$(this).find('a').css("color",colors[target]);
		});
	}
	for(j=0;j<5;j++) bindColor(blocks[j]);
	
        $('.citylist #msk').click(function(){$('.chooser_c').css('display','none');});
        $('.citylist #keme').click(function(){$('.chooser_c').css('display','none');});

	$(window).resize(function(){
		var obj = $(".wrapper").offset();
		var w = $(window).width();
		if(w<1064)
			$(".wrapper").offset({left:162,top:0}); 
		else 
			$(".wrapper").offset({left:w/2-$(".wrapper").width()/2,top:0});
	});
	

});


