var sliderw=0, w=705, timer, mi = false, ifd = 5000, ad = 600, isd = 3000;
$(document).ready(function(){
    if ($('.index_layer').length)  {
        index_gallery();
    }
    $('.index_layer').mouseover(function(){
        mi = true;
    }).mouseout(function(){
        mi = false;
    });
	
	$('.menu td.item:not("#selected_item")').hover(
		function(){ $(this).css({'background': 'url(/img/m_bg2.gif)'}); },
		function(){ $(this).css({'background': 'url(/img/emp.gif)'}); }
	);

	$('.menu td.item:not("#selected_item")').mousedown(
		function(){ $(this).css({'background': 'url(/img/m_bg1.gif)'}); return false;
	});
	
	$('#project_photo').click(function(){
	    if ($('.projects').length)
	        $($('.projects').get(0)).click();     
    });
	$('.projects').click(function(){
	    $('#project_photo').fadeOut('fast');
	    $('.projects').removeClass('pr_selected'); 
	    $(this).addClass('pr_selected');
	    $.post($(this).attr('href'), {}, function (data) {eval(data.replace(/^\s+|\s+$/g,"").replace(/[\r\n\f]+/g, '<br/>'));sliderw=0;if ($('#line_tab td').length > 1)$('.prev, .next').css({display: 'block'}); else $('.prev, .next').css({display: 'none'});   });
	    return false;
    });
    $(".prev").mouseover(function(){
        $(this).attr('src', '/image/b_prev.png');                
    }).mouseout(function(){
        $(this).attr('src', '/image/prev.png');                
    });        
    $(".next").mouseover(function(){
        $(this).attr('src', '/image/b_next.png');                
    }).mouseout(function(){
        $(this).attr('src', '/image/next.png');                
    });        
    $(".ilm").mouseover(function(){
        $(this).attr('src', $(this).attr('src').replace('1', '3'));                
    }).mouseout(function(){
        $(this).attr('src', $(this).attr('src').replace('3', '1'));                
    });        
    
	$(".prev").click(function(){
		var count = $('#line_tab td').size();
		sliderw = sliderw+1;
		if(sliderw == 1)
		{
			$('#line_tab tr td:last').clone().insertBefore($('#line_tab td:first'));
			$(".slider").css({marginLeft:-w});
			sliderw = sliderw-1;
			$('#line_tab tr td:last').remove();
		}
		$(".slider").animate({marginLeft:(sliderw*w)},300);
	});		
	$(".next").click(next);
	$(".index_projects").click(function(){
	    clearTimeout(timer);
	    $(".slider").css({marginLeft:-((parseInt($(this).attr('id').replace('id', '')))*w)});
	    return false;
	});
	$('#logout').click(function(){
	    if ($.cookie('dillerId'))
	    {
	        $.cookie('dillerPassword', null,{path: '/', domain: '.'+document.domain});
	        $.cookie('dillerId', null,{path: '/', domain: '.'+document.domain});	    
	    }
	    else 
	    {
	        $.post('/', {logout: 1}, function (data) {eval(data);});
	    }
	    window.location = '/';
	});
	$('.pr').click(function(){
	    window.location=$(this).attr('href');
	    return false;
	});
	$('.windowOpen').click(function() {
	    var w = 520, h = 450;
	    var wc=parseInt((screen.availWidth-w)/2) 
        var hc=parseInt((screen.availHeight-h)/2)
    	registration= open('/dilers/registration/', 'displayWindow', 'width='+w+',height='+h+',resizable=no,scrollbars=no,menubar=no,toolbar=no,location=no,statusbar=no,status=no,top='+hc+',screenY='+hc+',left='+wc+',screenX='+wc);
	    return false;
	});
	$('#windowClose').click(function() {
	    closeW();
	});
});
var next = function(){
		var count = $('#line_tab td').size()*-1;
		sliderw = sliderw-1;
		if(sliderw == count)
		{
			$('#line_tab tr td:first').insertAfter($('#line_tab td:last'));
			$(".slider").css({marginLeft:(sliderw+2)*w});
			sliderw = sliderw+1;			
		}
		$(".slider").animate({marginLeft:(sliderw*w)},ad);
	};
function index_gallery()  {
     timer=setTimeout("if (!mi) next();index_gallery();", (mi ? 500 : ($('#line_tab td:last').attr('id') == 'fr' ? ifd : isd))); 
}	
function gallery()  {
   timer=setTimeout("next();gallery();", 3000); 
}
function cform(a) {
$.post(a[0].action, a.serializeArray(), function (data) {eval(data);});  
}
function closeW()
{
//if (window.opener && !window.opener.closed){
//window.opener.location.reload();
//}
window.close();
}

function item_view(url, w, h) {
    var wc=parseInt((screen.availWidth-w)/2) 
    var hc=parseInt((screen.availHeight-h)/2)
	registration= open(url, 'displayWindow', 'width='+w+',height='+h+',resizable=no,scrollbars=no,menubar=no,toolbar=no,location=no,statusbar=no,status=no,top='+hc+',screenY='+hc+',left='+wc+',screenX='+wc);
}
function pu() {
    $(".ilm").mouseover(function(){
        $(this).attr('src', $(this).attr('src').replace('1', '3'));                
    }).mouseout(function(){
        $(this).attr('src', $(this).attr('src').replace('3', '1'));                
    }).mousedown(function(){
        $(this).attr('src', $(this).attr('src').replace('3', '2'));                
    }).mouseup(function(){
        $(this).attr('src', $(this).attr('src').replace('2', '3'));                
    });   
}
