$(document).ready(function(){
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
		$("#special_list_items a img").pngfix( { sizingMethod: "crop" } );
	}

	//Gallery
	var lift_floor = 0;
	var lift_offset = 158;
	var lift_viewport = 4;
	var lift_size = $("#special_list ul li").size();
	
	$("#special_list_wrapper ul").css('width', lift_size * lift_offset);

	$("#special_list_left a").click(function(event){
		if(lift_floor > 0){
			lift_floor--;
			$("#special_list_items").animate({left: -(lift_offset * lift_floor)},"slow");
		}
		return false;
		
	});

	$("#special_list_right a").click(function(event){
		if(lift_floor + lift_viewport < lift_size){
			lift_floor++;
			$("#special_list_items").animate({left: -(lift_offset * lift_floor)}, "slow");
		}
		return false;
	});
});

var opening=false;

function hideall() {
    if (opening==false){
        document.getElementById('selects').className='';
    }
    opening=false;
}
function showall() {
    if(opening==false){
        document.getElementById('selects').className='shown';
    }
    opening=true;
}

/* For forum
 *
 **/
function backToTheme(uri){
    window.location.href=uri;
}

function copyQ(autor) {
    txt='';
    if (window.getSelection&&!window.opera) txt = window.getSelection();
    else if (document.getSelection) txt=document.getSelection();
    else if (document.selection) txt=document.selection.createRange().text;
    txt='<div class="qu">'+autor+'<br>'+txt+'</div><br>';
}

function setCaret (textObj) {
    if (textObj.createTextRange) {
        textObj.caretPos = document.selection.createRange().duplicate();        
    }
}

function insertAtCaret (textObj, textV) {    
    textV=textV.replace(/\[\?\]/g,'');
    if (textV=='') return;
    var ver=8;
    if(document.all && !window.opera){
        if (textObj.createTextRange && textObj.caretPos) {
            var caretPos = textObj.caretPos;
            caretPos.text = (caretPos.text.charAt(caretPos.text.length - 1) == ' ') ?textV + ' ' : textV;
        } else {
            textObj.value += textV
        }
    } else {
        var brows = navigator.userAgent.toString();
        var scrollTop, scrollLeft;
        if (textObj.type == 'textarea' &&  typeof textObj.scrollTop != 'undefined'){
            scrollTop  = textObj.scrollTop;
            scrollLeft = textObj.scrollLeft;
        }                
        if(brows.search(/opera\/?(\d*.\d*)/i) != -1) ver = RegExp.$1;
        if(textObj.selectionStart>=0  && ver>=8){
            if(textObj.textLength != undefined){ 
                var selLength = textObj.textLength; 
                var selStart = textObj.selectionStart; 
                var selEnd = textObj.selectionEnd; 
                if (selEnd == 1 || selEnd == 2)  selEnd = selLength;  
                var s1 = (textObj.value).substring(0,selStart); 
                var s2 = (textObj.value).substring(selStart, selEnd) 
                var s3 = (textObj.value).substring(selEnd, selLength); 
                if (s2) textObj.value = s1 + textV + s2 + textV + s3; 
                else   textObj.value = s1 + textV + s3; 
                textObj.setSelectionRange(selStart+textV.length,selStart+textV.length); 
            } 
            if (typeof scrollTop != 'undefined'){
                textObj.scrollTop  = scrollTop;
                textObj.scrollLeft = scrollLeft;
            }
        } else {
            textObj.value+=textV;
        }
    }
}

function pasteQ(){
    wysiwyg_settext('newtext', '777');
    document.frames.wysiwygnewtext.document.body.innerHTML+=txt;
}

