//Fix image 
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}


//////////////////////


//DROP DOWN FOR HEADER COUNTRY SETTING ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}

//COUNTRY STATE AND OTHER SETTING ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\
//very basic from the header

//######################################################## JQUERY 
// when the document has fully loaded
$(document).ready(function()
{
        //login stuff 
        $('a.expand_div').click(function()
        {
                // when a hyperlink is clicked slideDown the box div
                // chose one of the following lines to uncomment
                //$('#box').slideDown('fast'); // text based speed
                $('#box').slideDown(500); // time based speed (ms)
        });
		
		        //browse brand
        $('a.brand').click(function()
        {
                // when a hyperlink is clicked slideDown the box div
                // chose one of the following lines to uncomment
                //$('#box').slideDown('fast'); // text based speed
                $('#brand').slideDown(900); // time based speed (ms)
        });
		
   		$("div#brandup").mouseout(function()
       		 {		
		      	$("div#brand").slideUp();	
		 });
		        //login stuff 
        $('a.emailfriend').click(function()
        {
                // when a hyperlink is clicked slideDown the box div
                // chose one of the following lines to uncomment
                //$('#box').slideDown('fast'); // text based speed
                $('#box1').slideDown(500); // time based speed (ms)
        });
		
		//regular slide and hide 
		$("a.login").click(function () {
      	$("#login").slideUp();
		$("#register").slideDown(700); // time based speed (ms)
    	});
		
		
		//for rounded box
			$(function(){
        $('div.inner').wrap('<div class="outer"></div>');
        $('div.inner').corner("round 10px").parent().css('padding', '2px').corner("round 10px")
		});
		
		$('area.log').click(function()
        {
        $("#allcontent").fadeIn(600);$('#box').slideDown(500);$('#load').fadeOut(600);
        });
		
	//round boxes
	$('#giftout').corner("round 13px");
	$('#giftin').corner("round 13px");
	$('#gifthead').corner("round 13px");
	
	//for news
	$('#mainnews').corner("round 10px");
	$('#mainreviews').corner("round 10px");
	$('#mainvideo').corner("round 10px");
	$('#mainused').corner("round 10px");
	$('#mainhot').corner("round 10px");
	$('#maingift').corner("round 10px");



		
	


		
}
);

//########################################### end jquery s

function searching()
{
var searsh;
searsh=document.getElementById("searsh").value;
if ( searsh == "" ) { return false ; };
window.location="http://www.audiominds.net/search/"+searsh
}

//######################################### FOR COUNTRY LOCATION
function setcountry(str) {
  var url = window.location.href;
  if(url.lastIndexOf("store=")<0) {
          if(url.lastIndexOf("?")<0) { window.location=url+"?store="+str; }
          else { window.location=url+"&store="+str; }
  }
  else if(url.lastIndexOf("store=")<0) {
    url = url.substring(0,url.lastIndexOf("store=")+6)+str;
         window.location=url;
  }
}
///######################################### RESIZE IMAGE
function resize(which, max) {
  var elem = document.getElementById(which);
  var m1 = max*(30/100);
  var m2 = max*(35/100);
  var maxx = max-m1;
  //check the rectangular size
  var width = elem.width/elem.height ;
  
  if ( width < 1.5 ) { var maxxx = max-m2 }
  else { var maxxx = max }
  
  if (elem == undefined || elem == null) return false;
  if (max == undefined) max = 100;
  if (elem.width > elem.height) {
    if (elem.width > max) elem.width = maxxx ;
  } 
  else {
    if (elem.height > max) elem.height = maxx;
  }
}