﻿$(document).ready(function() {
    initMenup();
	
	//SetupTooltips();

});
function showBigMenu(id){
 $('.submenu').hide()
 $('.submenu').css("opacity","1")
    $("#sub"+id).show();
    $("#sub"+id).animate({
    "opacity":"1"
    },0)
}
function hideBigMenu(id) {

    $("#sub" + id).animate({
        "opacity": "0"
    }, 0)
    $("#sub" + id).hide()
}
 function analyzeqstr(){
    var purl, indexq, qstr;
    purl = window.location.toString();
    //alert(purl)
    indexq = purl.indexOf('?');
    purl = purl.substr(indexq+1)
    qstr = purl.split('&')
    for(i=0;i<=2;i++){
    alert(qstr[i]);
    }
 }

	$(function() {
		var newstabsContainer = $('div.newstabs > div');
		$('ul.newsnav a').click(function(){
			newstabsContainer.fadeOut();
			newstabsContainer.hide();
			newstabsContainer.filter(this.hash).fadeIn();
			newstabsContainer.filter(this.hash).show();
			$('ul.newsnav a').removeClass('tabselected');
			$(this).addClass('tabselected');
			return false;
			
		}).filter('#nt1').click();
		
		  $('#searchTextInput').val('جستجو در سایت');
		  $('#searchTextInput').css('color','#777777')
	
		  var i =0;
		  var nlink = $('#news_holder p a').length;
		  	$('#news_holder p').each(function(i){
		  	 this.innerHTML += '&nbsp;&nbsp;<a href="' + $('#news_holder a').attr('href') + '"><img src="http://localhost/irandoc/images/new_win.gif" style="border:none"/></a>'
			});
	});
	


function initMenup() {

    $('.submenu').css("opacity", "0");
    $('.submenu').hide();

    $('.submenu').hover(
     function() {
         $(this).show();
         $(this).animate({
             "opacity": "1"
         }, 0)
         var $id = $(this).attr("id")
         $id = $id.substring(3, $id.length)
         $("#item" + $id).addClass("menuItemSelected")

     }, function() {
         $(this).animate({
             "opacity": "0"
         }, 0)
         $(this).hide()
         var $id = $(this).attr("id")
         $id = $id.substring(3, $id.length)
         $("#item" + $id).removeClass("menuItemSelected")
     })


 }
  	
	
	function nexttab(){
	var $tabs = $('#tabs').tabs();
	var selected = $tabs.tabs('option', 'selected'); 
    $tabs.tabs('select', selected +1); 
    return false;
	};

	function prevtab(){
	var $tabs = $('#tabs').tabs();
	var selected = $tabs.tabs('option', 'selected');
    $tabs.tabs('select', selected -1);
    return false;
	};
	



function stoprotatetabs(){
	 var spbtn = $('#btn_sp') 
	 if($(spbtn).attr('src')=='http://localhost/irandoc/images/btn_pause.png'){
		 $(spbtn).attr('src','http://localhost/irandoc/images/btn_play.png')
	 	 $('#tabs').tabs('rotate', 0);
	 }else if($(spbtn).attr('src')=='http://localhost/irandoc/images/btn_play.png'){
	 	 $('#tabs').tabs({ fx: { height: 'toggle', duration:500 } }).tabs('rotate', 3000);
	 	 $(spbtn).attr('src','http://localhost/irandoc/images/btn_pause.png') 
	 }
}
function search_clicked() {
    var searchinput = $("#searchTextInput")
    if ($(searchinput).val('جستجو')) {
        $(searchinput).val('')
    }
}
function search_keyd(e) {
    key = e.keyCode ? e.keyCode : e.charCode;
    if (key != 27) {
        if (key == 13) {
            searchTerm = $("#searchTextInput").attr("value")
            if (searchTerm.length > 1) {

                window.location = "/search/?search=" + searchTerm
            }
        }
        searchinput = $("#searchTextInput").attr("value")
        searchcontainer = document.getElementById("inputContainer")
        searchcancel = document.getElementById("btncancel")
        if (searchinput.length >= 0) {
            var t = $("#searchTextInput").attr("value"); //document.frmsearch.inputbox.value
            if (searchcancel == null) {
                searchcontainer.innerHTML += "<div id='btncancel' onclick='javascript:search_cancel();' style='position:relative;cursor:hand;float:left;margin-top:-17px;margin-left:-4px;z-index:10;border-top:0.5px white solid;'><img src='http://94.232.172.94/images/btncancel.gif' alt='cancel'/></div>"
                $("#searchTextInput").focus();
                $("#searchTextInput").focus();
                $("#searchTextInput").attr("value", t);
            } else {
                document.getElementById("btncancel").innerHTML = "<img src='http://94.232.172.94/images/btncancel.gif' alt='cancel'/>"
            }
        } else if (searchinput.length == 0) {
            if (searchcancel != null) {
                $("#btncancel").attr(innerHTML, "");
            }
        }
    } else {
        if (searchcancel != null) {
            searchinput.value = "";
            document.getElementById("btncancel").innerHTML = ""
            $("#searchTextInput").focus();
            $("#searchTextInput").focus();
        }
    }
}

function search_cancel() {
    $("#searchTextInput").val('');
    document.getElementById("btncancel").innerHTML = ""
    $("#searchTextInput").focus();
    $("#searchTextInput").focus();

}
   function menuon(){
   $("#menuparent").css("height", "100%")
   $("#menuparent").css("z-index", "1500")
    };
    
    function menuoff(){
   $("#menuparent").css("height", "232px")
    };

 function printViewDefault() {
        $("#navScript").remove();
        $("body").data("page",$("body").html())   
    
        $("#promotion").animate({opacity:"0"}, { queue: true, duration: 100 })
        $("#menucontainer").animate({opacity:"0"}, { queue: true, duration: 100 })
        $("#menu").animate({opacity:"0"}, { queue: true, duration: 100 })
        $("#navSteps").animate({opacity:"0"}, { queue: true, duration: 100 })
        $("#header_menu").animate({opacity:"0"}, { queue: true, duration: 100 })
        $("#footer").animate({opacity:"0"}, { queue: true, duration: 100 })
        $("#headerContainer").animate({ opacity: "0", height: "0px" }, 300, function() {
            $("body div").css("background", "none")
            $("#promotion").remove();
            $("#menucontainer").remove();
            $("#menu").remove();
            $("#navSteps").remove();
            $("#header_menu").remove();
            $("#footer").remove();
            $("#headerContainer").remove();
            $("body p").css("text-align", "justify")
            $("body p").css("padding", "3px")
            $("body div").css("margin-left", "0px")

            $("body div").animate({ width: "100%" }, 600, function() {
              //  $("body").html($("body").data("page"))
                
            })
        })
   }
