var $j = jQuery.noConflict();

$j(document).ready(function(){

//set login link
	if ($j.browser.msie && parseInt($j.browser.version)==7) $j("#top_menu a:contains('Вход')").attr('href','#TB_inline?height=210&width=230&inlineId=popup_login').addClass('thickbox');
	else $j("#top_menu a:contains('Вход')").attr('href','#TB_inline?height=190&width=230&inlineId=popup_login').addClass('thickbox');
	
	
//fixing menu	
	//$j("#top_menu .multi_a a").css("background","none");
	
//slideshow config
	$j(".expander").unbind("click");
	$j(".expander").bind("click", function() {
		if ($j(this).find("~ ul").is(":hidden")) $j(this).text("-");
		else $j(this).text("+");
		$j(this).find("~ ul").slideToggle(200); 
		setTimeout('reinit()',200);
                
		return false;
		});
	$j(".expander_text").bind("click", function() {
		$j(this).prev().click();		
		return false;
		});
	$j('.expander:first').click();
        $j('.htmlsitemap ul li ul li a:first').click();

//mask
	/*$j('body').append('<div class="black_mask"><img src="images/mask1.png" width="132" height="175" border="0" /></div>');*/
	$j('body').append('<div class="black_mask2"><img src="images/mask2.png" width="71" height="94" border="0" /></div>');


	if ($j.browser.msie && parseInt(jQuery.browser.version)>=7) {
		/*$j('.black_mask').hover(
			function () { $j('img', this).hide(); },
			function () { $j('img', this).show(); }
			);	*/
		$j('.black_mask2').hover(
			function () { $j('img', this).hide(); },
			function () { $j('img', this).show(); }
			);	
	}

	else {
		/*$j('.black_mask').hover(
			function () { $j('img', this).fadeOut(100); },
			function () { $j('img', this).fadeIn(100); }
			);	*/
		$j('.black_mask2').hover(
			function () { $j('img', this).fadeOut(100); },
			function () { $j('img', this).fadeIn(100); }
			);	
		}
	
		/*$j('.gallery ul li a:even').each(function() { $j(this).clone().insertBefore(this).end().addClass("top") });
		$j(".gallery ul li a.top").empty();
		$j('.black_mask').clone(true).prependTo(".gallery ul li a.top");
		$j('.gallery ul li .black_mask').show();*/
		
		$j('.preview ul li a').each(function() { $j(this).clone().insertBefore(this).end().addClass("top") });
		$j(".preview ul li a.top").empty();
		$j('.black_mask2').clone(true).prependTo(".preview ul li a.top");
		$j('.preview ul li .black_mask2').show();



//image gallery

    //var options = { 
    //    beforeSubmit:  showRequest,  // pre-submit callback 
    //   success:       showResponse  // post-submit callback 

    //}; 

       $j('.bigLink:first').addClass('selectedThumb');
	   $j('.selectedThumb').hide();
	   $j('.bigLink:first').next().addClass('selectedThumb');
     
       $j('.bigLink').bind('click',function(){
        
        if($j(this).is('.selectedThumb')){
        return false;
        }
        
        $j('.selectedThumb').show().removeClass('selectedThumb');
        
        var myString = new String($j(this).attr('rel'));
        
        var paramsArr = myString.split(','); 
        
        //alert(paramsArr[0]);
        var imgURL = paramsArr[0]+paramsArr[1]+paramsArr[2];
		var imgbigURL = paramsArr[0]+paramsArr[1]+"big_"+paramsArr[2];
        var imgHeight = paramsArr[5];
        var imgWidth = paramsArr[6];
        
        
        $j(this).addClass('selectedThumb');
		$j(this).hide();
		$j(this).next().addClass('selectedThumb');
        showPic(imgURL,imgbigURL,'','',imgWidth,imgHeight);
        
        //alert();
        
        });


// lightbox

	//$j('.picturecontainer a').lightBox();
		
		
		
});


function reinit() {
	if ($j.browser.msie && parseInt($j.browser.version)==6) $j('.scrollable').jScrollPane({showArrows:false, scrollbarWidth:11});	
	else $j('.scrollable').jScrollPane({showArrows:true, scrollbarWidth:11});	
	//alert();
}
 
 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $j.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
  //  alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
   // alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
   //     '\n\nThe output div should have already been updated with the responseText.');
   
}


	function doAndShow(src,url,width,height){
        //doImage(img,url,width,height);
       //alert(src);
       var img = new Image();
       $j(img).load(function(){
        
		$j('#maxImage').remove();
        $j(this).hide();
        
        $j('.picturecontainer a').append(this);
        
        $j(this).fadeIn(200);
        
		$j('#foto_big').css("background","none");
        
        }).attr('src',src).attr('id','maxImage');
        
		$j('.picturecontainer a').attr('href',url);
		//$('.picturecontainer a').unbind('click');
		//$('.picturecontainer a').bind('click',function(){ window.open(url,"",'height='+height+',width='+width+'') });
		// 
        // alert("aa");
        // jQuery('#maxImage').fadeIn('slow');
        // alert('a');
        //img.src=newImg.src;
         
    }
    
    
    function showPic(url,bigurl,title,descr,width,height) {
       var picSrc='assets/snippets/phpthumb/phpThumb.php?src='+url+'&q=100';     
       $j('#foto_big').css("background","url(images/loadinfo.gif) center no-repeat");
	   $j('#maxImage').fadeOut(200);
       doAndShow(picSrc,bigurl,width,height);
     }

