function popitup(url){
    newwindow = window.open(url, 'name', 'height=700,width=990,scrollbars=1, left=300, top=0');
    if (window.focus) {
        newwindow.focus()
    }
    return false;
}

function popUp(URL, w, h){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + w + ",height=" + h + ",left =20,top =20');")
}

var min = 14;
var max = 26;
function increaseFontSize(id){
    var p = document.getElementById(id);
    if (p.style.fontSize) {
        var s = parseInt(p.style.fontSize.replace("px", ""));
    }
    else {
        var s = 19;
    }
    if (s != max) {
        s += 1;
    }
    p.style.fontSize = s + "px"
}

function decreaseFontSize(id){
    var p = document.getElementById(id);
    
    if (p.style.fontSize) {
        var s = parseInt(p.style.fontSize.replace("px", ""));
    }
    else {
        var s = 19;
    }
    if (s != min) {
        s -= 1;
    }
    p.style.fontSize = s + "px"
}


var countRow = 2;

function addFriend(){
    if (countRow >= 11) {
        return;
    }
    oTable = document.getElementById('tellTable');
    oRow = oTable.insertRow(countRow);
    oRow.id = "row_" + countRow;
    oCell = oRow.insertCell(0);
    oCell.height = "30";
    oCell.align = "left";
    oCell.innerHTML = 'إسم صديقك:';
    oCell1 = oRow.insertCell(1);
    oCell1.innerHTML = '<input type="text" name="friendNames[]" class="inpttxt" />';
    oCell2 = oRow.insertCell(2);
    oCell2.align = "left";
    oCell2.innerHTML = 'بريد صديقك اللإلكتروني:';
    oCell3 = oRow.insertCell(3);
    //	oCell3.setAttribute("colspan" , "2" );
    oCell3.innerHTML = '<input type="text" size="30" name="friendEmails[]" class="inpttxt" /> <a href="javascript:removeFriend(' + countRow + ')">حــذف</a>';
    countRow++;
}

function removeFriend(id){
    var elem = document.getElementById("row_" + id);
    if (elem) {
        elem.parentNode.removeChild(elem);
        countRow--;
    }
}


//qumra scripts

var ua = navigator.userAgent.toLowerCase();
var divw = 0;
var divh = 0;

if (document.getElementById || document.all) 
    document.write('<div id="imgtrailer" style="position:absolute;visibility:hidden;"></div>')

function gettrailobject(){
    if (document.getElementById) 
        return document.getElementById("imgtrailer")
    else 
        if (document.all) 
            return document.all.trailimagid
}

function gettrailobj(){
    if (document.getElementById) 
        return document.getElementById("imgtrailer").style
    else 
        if (document.all) 
            return document.all.trailimagid.style
}

function truebody(){
    return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function hidetrail(){
    gettrailobject().innerHTML = " ";
    document.onmousemove = '';
    gettrailobj().visibility = "hidden";
}

function trailOn(thumbimg, imgtitle, imgscription, imgsize, filesize, credit, level, thw, thh, flvvid, samplepath){
    //if(ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1)
    //{
    gettrailobj().left = "-500px";
    divthw = parseInt(thw) + 2;
    
    if (flvvid) {
        var vidsample = samplepath + flvvid;
        newHTML = "";
        newHTML = newHTML + '<div align="center" style="width:' + thw + 'px; font-family: verdana; font-size: 11px; padding: 0px; border: 1px solid #333333; background-color: #FFFFFF; layer-background-color: #FFFFFF; background-image: url(images/img_load.gif); background-repeat: no-repeat;">';
        newHTML = newHTML + '<object  height="' + thh + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">';
        newHTML = newHTML + '<param name="movie" value="swf/flashthumb.swf">';
        newHTML = newHTML + '<param name="quality" value="best">';
        newHTML = newHTML + '<param name="loop" value="true">';
        newHTML = newHTML + '<param name="FlashVars" value="myfile=' + vidsample + '&watermarkvid=' + show_watermark_hover + '">';
        newHTML = newHTML + '<EMBED SRC="swf/flashthumb.swf" LOOP="true" QUALITY="best" FlashVars="myfile=' + vidsample + '&watermarkvid=' + show_watermark_hover + '"  HEIGHT="' + thh + '">';
        newHTML = newHTML + '</object><div align="left" style="padding: 3px;"><b>Title: </b>' + imgtitle + '<br><b>Description: </b>' + imgscription + '</div></div>';
        gettrailobject().innerHTML = newHTML;
    }
    else {
        gettrailobject().innerHTML = '<table><tr><td><div style="background-color: #000000; layer-background-color: #000000; border: 0pt none #000000; padding: 0pt; width:' + divthw + 'px;"><div style="background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px solid #000000; background-image: url(images/img_load.gif); background-repeat: no-repeat;"><center><img src="' + thumbimg + '" border="0"  height="' + thh + '"></center><div style="padding:3px"><b>Photgrapher name: </b>' + imgtitle + '<br><b>Location: </b>' + imgscription + '<br><b>Head Line : </b>' + imgsize + '<br></div></div></div></td></tr></table>';
    }
    
    
    gettrailobj().visibility = "visible";
    divw = parseInt(thw) + 25;
    divh = parseInt(thh) + 130;
    document.onmousemove = followmouse;
    //}
}

function followmouse(e){
    var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
    var docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
    if (typeof e != "undefined") {
        if (docwidth < 15 + e.pageX + divw) 
            xcoord = e.pageX - divw - 5;
        else 
            xcoord = 15 + e.pageX;
        if (docheight < 15 + e.pageY + divh) 
            ycoord = 15 + e.pageY - Math.max(0, (divh + e.pageY - docheight - truebody().scrollTop - 30));
        else 
            ycoord = 15 + e.pageY;
    }
    else 
        if (typeof window.event != "undefined") {
            if (docwidth < 15 + truebody().scrollLeft + event.clientX + divw) 
                xcoord = truebody().scrollLeft - 5 + event.clientX - divw;
            else 
                xcoord = truebody().scrollLeft + 15 + event.clientX;
            
            if (docheight < 15 + truebody().scrollTop + event.clientY + divh) 
                ycoord = 15 + truebody().scrollTop + event.clientY - Math.max(0, (divh + event.clientY - docheight - 30));
            else 
                ycoord = truebody().scrollTop + 15 + event.clientY;
        }
    gettrailobj().left = xcoord + "px"
    gettrailobj().top = ycoord + "px"
}



//Main slider
$(document).ready( function(){
    //Show Banner
    $(".main_image .overdesc").show(); //Show Banner
    $(".main_image .desc").animate({
        opacity: 0.7
    }, 1); //Set Opacity
    //Click and Hover events for thumbnail list
    
    var oldID = '';
    var newID = '';
    
    $(".image_thumb ul").find('li.on').everyTime(10000, 'featured', function(){
        oldID = $(".image_thumb ul").find('li.on').attr('id');
        newID = $(".image_thumb ul").find('li.on').next().attr('id');
        if (newID == undefined) {
            newID = 'feature-0';
        }
        
        $('#' + oldID).removeClass('on');
        $('#' + newID).addClass('on');
        
        //Set Variables
        var imgAlt = $('#' + newID).find('img').attr("alt"); //Get Alt Tag of Image
        var imgAltHref = $('#' + newID).find('.desc .lititle a').attr("href"); //Get Alt Tag of Image
        var imgURL = $('#' + newID).find('a').attr("alt"); //Get Main Image URL
        var imgDesc = $('#' + newID).find('.desc').html(); //Get HTML of block
        var imgDescHeight = $(".main_image").find('.desc').height(); //Calculate height of block	
        //Animate the Teaser				
        $(".main_image .desc").animate({
            opacity: 0,
            marginBottom: -imgDescHeight
        }, 250, function(){
            $(".main_image .desc").html(imgDesc).animate({
                opacity: 0.7,
                marginBottom: "0"
            }, 250);
            $(".main_image img").attr({
                src: imgURL,
                alt: imgAlt
            });
            $(".redtitle").html('<a href="' + imgAltHref + '">' + imgAlt + '</a>');
        });
    });
    
	$(".image_thumb ul li").click(function(){
		var url = $(".image_thumb ul").find('li.on').find('.desc .lititle a').attr("href");
		$(location).attr('href',url);
	});
});

function showkebord(id, id2){
    $("div#" + id).slideToggle();
    $("div#" + id2).hide();
}

