$(function(){
	
	$("ul.menuHeader").superfish({
		 delay:250
	}); 
	
	$("a[rel='blank']").bind('click',function(){
		window.open($(this).attr('href'));
		return false;
	})

		
	$('a.our_works').bind('click',function(){
		var id_works = $(this).attr('id').split('_')[1];
		$.post('our-works.html',{ works: id_works}, function(data) {
			
			if($('#dialog').size() == 0) var mdialog = $('<div>').attr('id','dialog').hide().appendTo('body');
			else  var mdialog = $('#dialog');
			$('#dialog').html($(data).find('.cb').html());
			
			$('#dialog').dialog({	
				modal:true,
				resizable: false,
				width:900,
				height:650,
				open:function(){
					var self_win = $(this);
					self_win.css('opacity','0').animate({
						opacity: 1
					}, 800)

					$(this).find('a').filter(function(){
						if($(this).attr('class') !=='' && $(this).attr('class') == 'close_dial') return true;
						else return false;
					}).bind('click',function(){
						self_win.dialog("close"); 
					})
				},
				dialogClass: "flora"
			});
			
			if(($.browser.msie && $.browser.version != '6.0') || !$.browser.msie ) $('.flora.ui-dialog').css({position:"fixed"});
			if($('.slider_photo').size() !=0){
				$('a.click_preview').bind('click',function(){
					var path= $(this).find('img').eq(0).attr('src');
					$('div.big_images a img','#project_works').fadeOut(400,function(){
						$(this).attr('src',path.replace(/small/i, "big"));
						$(this).fadeIn(600);
					})	
				})
			}			
		},"html");
		return false;
	})
	
	
	var Eskiz_clients = (function() {
		function  openWin(html){
			if($('#dialog').size() == 0) var mdialog = $('<div>').attr('id','dialog').hide().appendTo('body');
			else  var mdialog = $('#dialog');
			if(html !='') $('#dialog').html(html);
			$('#dialog').dialog({	
				modal:true,
				resizable: false,
				width:750,
				height:650,
				open:function(){
					var self_win = $(this);
					self_win.css('opacity','0').animate({
						opacity: 1
					}, 800)
					var iterval;
					//event close
					$('div.ui-widget-overlay').bind('click',function(){
						self_win.dialog('close');
						if(iterval !='undefined') window.clearInterval(iterval);
					})
					//event close
					$(this).delegate("a.close_dial", "click", function(){
						self_win.dialog('close');
						if(iterval !='undefined') window.clearInterval(iterval);
					});
					//event next
					$(this).delegate('a.next',"click",function(){
						next(self_win);
					})
					//event prev
					$(this).delegate('a.prev',"click",function(){
						prev(self_win);
					})
					//event play
					$(this).delegate('a.play',"click",function(){
						iterval = play(self_win);
					})
					//event pause
					$(this).delegate('a.pause',"click",function(){
						if(iterval !='undefined') window.clearInterval(iterval);
					})
					
				},
				dialogClass: "flora"
			});
			if(($.browser.msie && $.browser.version != '6.0') || !$.browser.msie ) $('.flora.ui-dialog').css({position:"fixed"});
		}
		function closeWin(win){
			win.animate({
				opacity: 0
			}, 1000,function(){
				win.dialog('close');	
			})
		}
		function prev(win){
			var id = parseInt(win.find('#id_cl').val());
			$.post('core/clients.php',{cur_id:id,mtd:'getPrev'},function(data){
				if(data != '') {
					//closeWin(win);
					openWin(data);
				}
			})
		}
		function play(win){
			 return window.setInterval( function() {
				 next(win);
			 }, 5000 );
		}
		function next(win){
			var id = parseInt(win.find('#id_cl').val())
			$.post('core/clients.php',{cur_id:id,mtd:'getNext'},function(data){
				if (data != '') {
					//closeWin(win);
					openWin(data);
				}
			})
		}
		/*cache*/
		return {
			init :function(){	
				$("div.our_cliens div:not(.title) a").bind('click',function(){
					var id_client = parseInt($(this).attr('id').replace('id_',''));
					if(!isNaN(id_client) && id_client !=0){
						$.post('core/clients.php',{ id: id_client,mtd:'_getById'},function(data){
							openWin(data);
						})
					}
				})
			}
		}
	}());
	Eskiz_clients.init();
	
	//$("body").snowing();

});

